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

Does Anyone Still Use Backticks?

66 views
Skip to first unread message

lawren...@gmail.com

unread,
Oct 2, 2016, 10:01:59 PM10/2/16
to
Instead of

cmd1 ... `cmd2 ... ` ...

use

cmd1 ... $(cmd2 ... ) ...

Advantages:
* Paired bracketing symbols allow easy nesting.
* Larger symbols are easier to see.

Rakesh Sharma

unread,
Oct 3, 2016, 12:36:28 AM10/3/16
to
$() also invokes it's own quoting context, thereby at once curing
backslashitis, e.g. compare the two

eval "`printf '\"${%s}\" ' \`fischer_yates \\\`countupto \"$#\"\\\`\``"
eval "$(printf '"${%s}" ' $(fischer_yates $(countupto "$#")))"

The backticks suffer from an inconsistency problem, like as:
echo '\$var'; # will output as expected: \$var
echo `echo '\$var'`; # outputs: $var
echo $(echo '\$var'); # outputs: \$var

Chris F.A. Johnson

unread,
Oct 3, 2016, 1:08:06 AM10/3/16
to
I only use backticks at the command line.

In scripts, I always use $(...)

--
Chris F.A. Johnson

Janis Papanagnou

unread,
Oct 3, 2016, 1:27:58 AM10/3/16
to
> Subject: Does Anyone Still Use Backticks?

No. Not since ksh88, around 25+ years ago.
And especially to avoid a quoting mess.

Janis

John McCue

unread,
Oct 3, 2016, 6:45:46 PM10/3/16
to
lawren...@gmail.com wrote:
> Instead of
>
> cmd1 ... `cmd2 ... ` ...
>
<snip>

yes I do

Also, in the future, can you also put the question
in the body. Some news readers will cut off the
Subject. Granted in this case for me it was OK
because it is a short question, but if someone
reads my response without seing the subject they
will have no idea what I am saying.

John

lawren...@gmail.com

unread,
Oct 3, 2016, 9:35:55 PM10/3/16
to
On Tuesday, October 4, 2016 at 11:45:46 AM UTC+13, John McCue wrote:
> yes I do

Why?

Kaz Kylheku

unread,
Oct 3, 2016, 9:50:06 PM10/3/16
to
On 2016-10-03, John McCue <jmc...@jmcnet2.bstnma.east.verizon.net> wrote:
> lawren...@gmail.com wrote:
>> Instead of
>>
>> cmd1 ... `cmd2 ... ` ...
>>
><snip>
>
> yes I do

They have collars against ticks at PetSmart.

Free shipping for orders over $50.*

---
* That was a wild guess. Then I checked petsmart.com; it's actually $49.

John McCue

unread,
Oct 4, 2016, 9:07:14 PM10/4/16
to
Old habits I guess, a very long time ago I copied
a script that used $() and it had issues on the
UN*X I had access to. So never changed over, also
my eyes are use to seeing the ticks

John

Michael Paoli

unread,
Oct 6, 2016, 4:17:59 AM10/6/16
to
On Sunday, October 2, 2016 at 7:01:59 PM UTC-7, lawren...@gmail.com wrote:
>Subject: Does Anyone Still Use Backticks?
> Instead of
> cmd1 ... `cmd2 ... ` ...
> use
> cmd1 ... $(cmd2 ... ) ...

Yes, certainly sometimes.
E.g. in simple non-nested short(ish) command,
also for (extreme) backwards compatibility,
and also sometimes to avoid drain bamaged bash(1) bug.

So, e.g., very simple non-nested:
hostname=`hostname`
bit less typing, quite clear enough, highly backwards compatible
but lacks matched pairing.

Got nasty bash bug?
For many bash versions (I still sometimes hit such on production
systems), an intermix of case statements using ) rather than () pairs
in case, along with $() command substitution, runs into a nasty
bug in bash. Using `` instead of $() avoids that bug.
Other work-around for that bug is use newer alternative case
syntax that allows for matched () in case pattern matching.

And, if one needs much backwards compatibility or relatively extreme
portability, using backticks is highly reliable in that regard.

So, yes, I do still use backticks for command substitution, ... though
I do also use $(). Which I'll use, quite depends on context.

Sven Mascheck

unread,
Oct 6, 2016, 6:33:49 PM10/6/16
to
Michael Paoli wrote:
> On Sunday, October 2, 2016 at 7:01:59 PM UTC-7, lawren...@gmail.com wrote:
>>Subject: Does Anyone Still Use Backticks?
>> Instead of
>> cmd1 ... `cmd2 ... ` ...
>> use
>> cmd1 ... $(cmd2 ... ) ...

Another weak but valid argument pro $(): `` can be confused with ''.

> and also sometimes to avoid drain bamaged bash(1) bug.

Not only in bash: www.in-ulm.de/~mascheck/various/cmd-subst/

Another interesting corner case bug, (like most of these bugs a quite
weak argument against $(), but good to keep in mind that they exist),
ksh88 prints "double quotes" "single quotes" for

echo $(cat << EOF
"double quotes"
'single quotes'
EOF
)
0 new messages