lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Jul 12, 2010 at 4:51 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> 1. Even if we would be able to design the library in such way, we
> still should provide escaping — just in case we missed some case
> somewhere.
>
> 2. Please suggest the interface for the library that avoids the need
> for escaping. :-)



the point to remember is that a posix process invocation is _not_ a
text line; it's a list of C strings.

a huge part of the pain in programming shell scripts is fighting
against the need of the shell to parse the command line into that
string list; therefore you get quotes, and escapes, and lots of
variable extension rules you have to memorize.   if you go the route
of parsing a 'command line', you'll likely get the same issues.

OTOH, if you keep the Lua syntax (as it seems from the latest examples
on the thread); you don't have to worry about parsing, that's done by
the Lua compiler.  and yes, Lua does have it's own set of escaping
rules, but these are so much simpler and saner than any shell's.
precisely because they're limited to building strings; after they're
built, they're threated as opaque binary data, and there's no need to
further process them before using them to spawn a subprocess.

of course, some simple templating (maybe like python's string
interpolation) might be desirable (*); but it should be an extra
facility, not a forced part of the data flow.

that way, you don't have to worry that a filename might contain
spaces, or quotes, or any 'nasty' characters; Lua doesn't care,
excecvp() doesn't either (except for embedded '\0's, unfortunately)


(*): this is what i use when i find myself using string.format() too much:

	function string:template(variables)
		return (self:gsub('{%%(.-)%%}', function (key) return
tostring(variables[key] or _G[key] or '') end))
	end


-- 
Javier