Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why are backticks deprecated?

20 views
Skip to first unread message

Hans Meier

unread,
Apr 28, 2008, 6:21:36 AM4/28/08
to
Hi,

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

Dave B

unread,
Apr 28, 2008, 6:34:48 AM4/28/08
to

Janis

unread,
Apr 28, 2008, 7:59:50 AM4/28/08
to

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.

Stephane CHAZELAS

unread,
Apr 28, 2008, 8:06:52 AM4/28/08
to
2008-04-28, 12:34(+02), Dave B:
[...]

>> 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.
[...]

`...` 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

Dave B

unread,
Apr 28, 2008, 8:33:49 AM4/28/08
to
On Monday 28 April 2008 14:06, Stephane CHAZELAS wrote:

> `...` 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.

Sven Mascheck

unread,
Apr 28, 2008, 6:40:08 PM4/28/08
to
Hans Meier wrote:

> 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
)

0 new messages