help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] pass command to script


From: Warlich, Christof
Subject: Re: [Help-bash] pass command to script
Date: Fri, 26 Apr 2019 14:48:59 +0000

Chet Ramey wrote:
> Keywords are reserved words like `for' and `case' that introduce or
> are part of compound commands. Builtins are, well, builtin commands.
> The `time' reserved word just indicates that the following command
> should be timed, which is performed internally. That's how bash can
> time pipelines and compound commands.

Ok, this explains why it's so "well behaving" when some arbitrary command
is being timed.

> > But what I am really interested in is you guys (and girls! 😊) view on
> > whether it would be desirable (and implementable with affordable effort)
> > to add some form of a nestable quoting mechanism (e.g. something like
> > $[...]) to bash for the reasons I tried to point out in my previous post.

> The $'...' form of quoting comes pretty close, but anything can fail when you
> expand the words and arbitrary number of times.

Yes, I know (i.e. I just found out today 😉) that $'...' comes pretty close. And 
as
much as I can see, it even allows an arbitrary depth of nesting as long as no
ordinary single quotes are used, e.g.:

$ bash -c $'echo "hi"'  
hi
$ bash -c $'bash -c $\'echo "hi"\''
hi
$ bash -c $'bash -c $\'bash -c $\\\'echo "hi"\\\'\''
hi

But as can be seen from these examples, every additional quoting layer that's
being wrapped around requires the command string _being_ wrapped to be
modified by adding appropriate escaping.

Now let's assume we had some nestable quoting mechanism similar to the
already suggested $[...]. Then, escaping would not be necessary at all, right?:

$ bash -c $[echo "hi"]  
hi
$ bash -c $[bash -c $[echo "hi"]]
hi
$ bash -c $[bash -c $[bash -c $[echo "hi"]]]
hi

Passing _such_ a command line to a script would merely require to wrap this
command with another $[...] without the need to modify anything _inside_
that command line!

Doesn't that look rather appealing?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]