[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as replacement for Bash scripting
- From: Alexander Gladysh <agladysh@...>
- Date: Tue, 13 Jul 2010 01:27:27 +0400
On Mon, Jul 12, 2010 at 20:57, Hisham <hisham.hm@gmail.com> wrote:
> On Mon, Jul 12, 2010 at 6:51 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Shifting subjects a little, here's an idea that popped in my head
> yesterday and that may be a little controversial. I'd like to know
> everyone's opinions about this:
> -- typical sh.run invocation, nothing new
> x = sh.out.grep("foo", "/usr")
> -- I expect us to use a lot of stuff like
> -- some of these variations:
> x = sh.out.sort("-n", 1, "file.txt")
> x = sh.out.sort("-n1", "file.txt")
> x = sh.out.sort("-n"..x, "file.txt")
> -- in any case, writing arguments can get annoying fast.
> -- so how about this:
> x = sh.out.sort({n=1}, "file.txt")
> -- yes, table arguments get translated into -flags.
OK.
> if sh.ok.find("/etc", {name="*rc", ctime="+30"}) then ...
OK.
> -- Sub-proposal:
> -- if the order of arguments doesn't matter, we could
> -- even get more arguments from the array part
> x = sh.out.sort {n=1, "file.txt"}
So, if order does matter, we have something like this?
sh.ok.foo("/bar", { baz = 1 }, { quo = 42 })
Still looks fine.
BTW. Perhaps I've missed it in the earlier discussion, but why do we
write calls in reverse?
Isn't this better? It would allow some fancier chaining if we need one:
if sh.find("/etc", {name="*rc", ctime="+30"}).ok() then ...
You may make traling braces optional with some __index work:
if sh.find("/etc", {name="*rc", ctime="+30"}).ok then ...
If we have table constructor as a single argument, we probably may
write it like this:
x = sh.sort {n=1, "file.txt"} ().out
> -- Open issue: -flags vs. --flags.
> -- For simplicity, I propose single-dash -flags only.
I think that, maybe, --flags are more useful in shell scripts — they
are more readable.
Also, we may look at first char of the flag name, and don't change it
if it is "-":
x = sh.sort {["-n"]=1, "file.txt"} ().out
Btw, Windows programs often use "/" instead of "-".
> My first impression is that this could improve readability, and
> further reduce escaping/concatenations. OTOH it could bring confusion
> when argument order matters, and, in general, the whole thing may be
> overkill. Any impressions?
Looks useful and not too hard to implement.
Alexander.
- References:
- Lua as replacement for Bash scripting, Alexander Gladysh
- Re: Lua as replacement for Bash scripting, Jerome Vuarand
- Re: Lua as replacement for Bash scripting, Alexander Gladysh
- Re: Lua as replacement for Bash scripting, Jerome Vuarand
- Re: Lua as replacement for Bash scripting, Hisham
- Re: Lua as replacement for Bash scripting, Alexander Gladysh
- Re: Lua as replacement for Bash scripting, Florian Weimer
- Re: Lua as replacement for Bash scripting, Javier Guerra Giraldez
- Re: Lua as replacement for Bash scripting, Alexander Gladysh
- Re: Lua as replacement for Bash scripting, Hisham