If I want to something like:
foo="bar baz"
foo='bar baz'
Is it best practice to use double-quotes or single-quotes?
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.
I tend to use double quotes unless I really need to use single quotes to stop variable interpolation or for other reasons.
Maybe this is part of my growing up with languages like Pascal, Fortran, and Basic which used double quotes and not single quotes. However, since most of the strings you use in BASH will do variable interpolation, you might as well get in the habit of using double quotes instead of thinking whether you need double quotes or single quotes in a statement. Also you’re variable might be:
now, but when you modify it:
You don’t have to also remember to edit the quotes while, you’re at it.
In the few situations where you actually need single quotes, you can easily mentally shift the other way around.