command substitution (was: wget and captcha puzzle !!!)
* Tony Baldwin wrote on 2012-01-21 at 12:15 (-0500):
> Why use $(command) instead of `command`?
> Generally, I've always used $(command), but see scripts all
> over using `command`, and wondered if there were advantages of
> one over the other. It seems they give the same result, no?
Some do, some don't :-) See some curious examples on
http://tldp.org/LDP/abs/html/commandsub.html
For short, I think you should use $(...) and try to avoid `...`.
Also keep in mind that in Debian /bin/sh -> dash
----------test1.sh----------
#!/bin/sh
set -xv
echo `echo \\`
echo $(echo \\)
----------------------------
$ ./test1.sh <-------- same output as dash ./test1.sh
echo `echo \\`
+ echo \
+ echo \
\ <-------- Watch this...
echo $(echo \\)
+ echo \
+ echo \
\
$ bash ./test1.sh
echo `echo \\`
echo \
++ echo
+ echo
<-------- ...and this!
echo $(echo \\)
echo \\)
echo \\
++ echo '\'
+ echo '\'
\
Mathias
Reply to: