I wonder why backticks are deprecated. Is there any functional or
technical difference between backticks and $() notation beside $() is
called to be more "visible" and "distinguishable" from '' than ``?
I'm interested in your opinion.
Regards,
Hans
Besides all the FAQ points there's also the consistency as a lexical
token; the $(...) "subshell expansion" is closely related to (...)
"subshell" (and not the least related with any semantical meaning of
quoting in shell), and makes it more apparent that (typically) a new
costly shell instance is involved.
Janis
>
> --
> D.
`...` are a pain to nest especially when combined with double
quotes. It's harder to read as the opening and closing ones are
not visually differentiated. You have to pay close attention to
backslashes inside \. Typically a given piece of code may do
different things when inside backticks and with not.
For instance,
a=`printf %s '\\'`
assigns "\" to $a, while:
printf %s '\\'
outputs "\\".
That's because the \ inside `...` is overloaded to allow nested
`...`.
--
Stéphane
> `...` are a pain to nest especially when combined with double
> quotes. It's harder to read as the opening and closing ones are
> not visually differentiated. You have to pay close attention to
> backslashes inside \. Typically a given piece of code may do
> different things when inside backticks and with not.
>
> For instance,
>
> a=`printf %s '\\'`
>
> assigns "\" to $a, while:
>
> printf %s '\\'
>
> outputs "\\".
>
> That's because the \ inside `...` is overloaded to allow nested
> `...`.
And, to reinforce:
$ a=`printf %s "\\"`
-bash: command substitution: line 1: unexpected EOF while looking for
matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
$ a=$(printf %s "\\")
$ # works fine
--
D.
> Is there any functional or
> technical difference between backticks and $() notation
Yes; and it can be fun defending backticks, e.g. see the discussion
1181880379.8...@i13g2000prf.googlegroups.com ff.
--
echo $( cat<<eof
body contains )
eof
)