Difference between $() and ``

Jan 13, 2015 at 9:43am
Hello,
Are these 2 different ?

1
2
3
content=`cat file`

content=$(cat file)


when I echo them out , I receive the same result , but does shell handle them
the same ? or not ?

Thanks
Last edited on Jan 13, 2015 at 9:44am
Jan 13, 2015 at 11:45am
Which shell? Bash?

Read section "Command substitution" from
man bash
Jan 13, 2015 at 4:50pm
If you could tell me for both that would be great
Jan 13, 2015 at 5:43pm
I just did.

I will not copy text here, because you are better off by learning to read the manual.

Note: man-pages are online too, if you don't have them installed.
Jan 14, 2015 at 1:08pm
They are identical in bash.
Google: Advanced Bash Scripting
Last edited on Jan 14, 2015 at 1:08pm
Jan 14, 2015 at 2:03pm
In the Korn shell, the grave accents style ('') is obsolete. It's also slower than $().
Jan 14, 2015 at 4:38pm
http://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution writes:
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by ‘$’, ‘`’, or ‘\’. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.

Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes.

I.e. not identical.
Topic archived. No new replies allowed.