What are the differences between the following variables in regards to scripting with BASH:
$var
"$var"
${var}
"${var}"
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.
There is no difference between
$varand${var}and there is no difference between"$var"and"${var}", except that in certain cases the parser may not be able to identify your intent when you user the former versions. Consider:The first
echoprints nothing, because the variablefooworldis not defined. The second printshelloworldbecause the shell was able to determine that you were referencing thefoovariable.The difference between
$varand"$var"is that unquoted variable expansions are evaluated by the shell after the expansion. As such:Lists
/, because after the expansion the shell evaluates the space as a token separator, whereasResults in
ls /: No such file or directorybecause no command namedls /is available in the user’s environment.