Today I noticed if I run:
ldd `which bash`
I get the expected output. But when I run
ldd 'which bash'
I get error ./which bash: No such file or directory.
So what is the difference between the two similar looking symbols?
The ` is named a backquote, to evaluate a command.
The backquote is used in the old-style command substitution, e.g.
foo=`command`
The
foo=$(command)
syntax is recommended instead. Backslash handling inside $()
is less surprising, and $()
is easier to nest.
See http://mywiki.wooledge.org/BashFAQ/082
The single quote ' is used to prevent shell expansion from strings:
Learn how to quote properly in shell, it's very important :
"Double quote" every literal that contains spaces/metacharacters and every expansion:
"$var"
,"$(command "$var")"
,"${array[@]}"
,"a & b"
. Use'single quotes'
for code or literal$'s: 'Costs $5 US'
,ssh host 'echo "$HOSTNAME"'
. See
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
when-is-double-quoting-necessary