[Top][All Lists]

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

[Help-bash] pass command to script

From: Warlich, Christof
Subject: [Help-bash] pass command to script
Date: Fri, 26 Apr 2019 07:24:01 +0000

> $ time var="Hello cruel" bash -c 'echo "${var} world!"; sleep 2; echo 
> "Goodbye World!"'
> Hello cruel world!
> Goodbye World!
> real    0m2,007s
> user    0m0,001s
> sys    0m0,006s

Thanks for all of your enlightening comments, though I'm a bit disappointed 
that no one addressed why bash's "time" builtin obviously does so well! Sure, 
as a builtin, it may "see" the string being passed _before_ it has been 
tinkered with by the shell. Nevertheless, I wonder if that very fact could lead 
one way to find a good solution?! Considering programs like ssh, it looks like 
there are quite a few applications that would significantly benefit.

Pondering on how to pass commands to a script _without_ having the shell 
tinkering with it before, enclosing the whole command string into single quotes 
comes into mind - but unfortunately, this fails miserably when the command 
itself contains single quotes. Even any attempt to escape inner single quotes 
seems to be doomed. E.g., the following causes the shell to to ask for further 

$ ls '\'foo\''

Obviously, single quotes even prevent the backslash to be interpreted by the 

Luckily, $'...' quoting comes to a rescue here:

$ ls $'\'foo\''
ls: cannot access 'foo': No such file or directory

But it just adds only _one_ additional layer of nesting, so it is still easy to 
find examples of command lines (that already used up all possible quote-nesting 
by itself) that would not work. Furthermore, the backslashes really look ugly.

To me, the almost prefect solution would be if bash offered some sort of 
nestable quotes right away, e.g. something like $[], which may not already be 
in use afaik. What do you think? Would this be a desirable (and decently easily 
implementable) feature for bash?



reply via email to

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