As far as I’ve seen there are two ways to initialize a variable with the output of a process. Is there any difference between these two?
ex1=`echo 'hello world'`
ex2=$(echo 'hello world')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You get same effect.
The
$()is recommended since it’s more readable and makes it easier to nest one$()into another$().Update:
The
$()syntax is a POSIX 1003.1 standard (2004 edition). However, on some older UNIX systems (SunOS, HP-UX, etc.) the/bin/shdoes not understand it.You might need to use backtick “`” instead or use another shell (usually it’s ksh) if you need your script to work on such environment.
If you don’t know which syntax to use – use
$(). Backtick syntax is deprecated.