You are not logged in.
Hey,
i'm new to bash scripting but I'm using both of the syntaxes `` and $() quite often and they seem to do the same thing.
I believe `` just evaluates and with $() i can do an array of evaluating sequences but i'm not sure and i didn't want to dig in too deep into some bash guides right now.
Can you tell me where the difference is?
Last edited by demian (2010-05-14 13:16:52)
no place like /home
github
Offline
AFAIK you can nest $(one$(two$(three))) but now ``.
Ogion
(my-dotfiles)
"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
"Enlightenment is man's leaving his self-caused immaturity." - Immanuel Kant
Offline
AFAIK you can nest $(one$(two$(three))) but now ``.
That is the main difference. For that reason the `` syntax is sort of depricated, but it has been in use so long that it will always be around.
Offline
I don't think $() is portable outside of bash. That's what I've heard, anyway.
Offline
dash supports $(), and that's about as close to a strict POSIX shell as I've ever used.
Offline
zsh also supports $(). You should always use $(), it's nestable and easier to read.
Offline
To nest when using the backquoted form, escape the inner backquotes with backslashes.
But $() is indeed more readable.
Offline
A quick web search turns up various relevant reasons, most already listed here.
note - Google doesn't seem to recognize '`' and '$()' in a query, so use 'backtick' instead.
Last edited by Peasantoid (2010-05-14 19:37:56)
Offline
man bash wrote:To nest when using the backquoted form, escape the inner backquotes with backslashes.
But $() is indeed more readable.
Proof:
echo $(echo $(echo $(ls)))
vs.
echo `echo \`echo \\\`ls\\\`\``
Offline
I don't think $() is portable outside of bash. That's what I've heard, anyway.
$() is adopted and recommended by POSIX, so protability should not be a problem.
Search for command substitution in google and see by yourself
Last edited by eirika (2010-05-14 20:24:57)
Offline
Okay, okay, I can take a hint Apparently I was misinformed. I wonder where I picked that up.
Offline