The difference between $(command) and `command`

In the for loop, we always write like
for CurUser in $( cut -f 1 -d : /etc/passwd )
do
...
done
or
for CurUser in `cut -f 1 -d : /etc/passwd`
do
...
done
Is there any difference between them ?
thanks !

The `backticks` syntax is the old style command substitution which does not allow nesting.

It does allow nesting, but the inner backticks must be escaped.

The backtick version can be used in all Bourne-type shells; the other works in all POSIX shells (ksh, bash, etc.).

It is easier to nest the second version; if you nest backticked substitution, you have to escape the inner backticks.

You should also note that that is almost always the wrong way to read a file (not to mention the useless use of cat):

while IFS=: read CurUser junk
do
   ...
done < /etc/passwd

I was of the notion, nesting of backticks is not possible,

as said escaping the inner backticks worked,

head `ls -1 \`echo "abhead"  |sed 's/^..//'\``

Thanks! :slight_smile: