Difference between ' ' and " " in bash scripting language

Hello guys,

I started studying a bit of bash scripting language, and I am not able really to understand what is the difference between using e.g.

echo "this is a string"


and using

echo 'this is a string'


They seem to be interchangeable in this simple example, but I have a strong feeling that they have different uses when it comes to more complicated topics such as variables, evaluations of expressions, usage of bash functions...

Can anyone explain to me what is the difference?

Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Welcome to ask.fedora. Yes, there are differences, depending on how and where you use them. I'm no expert on such things, so instead of trying to answer your question directly, and probably getting it wrong, I'll send you to this Guide to Advanced Bash Scripting that probably has more info than you need right now. I hope it's as useful to you as it has been to me on several occasions. Please feel free to ask more questions, because that's what we're here for.

more

Thanks a lot for the link. While it is indeed much more detailed than a new user would need it to be in order to get the basics, it has very good information inside and has already answered some other questions I had about the "Quoting" topic.

To anyone interested, the section "5 Quoting" has some examples of quoting and clear explanations (and also some complex examples for the advanced among us with not so clear explanations; but I'm sure it's because I am not among the advanced :D)

( 2016-01-07 15:33:35 -0500 )edit

To make it simple:

We use single quotes (') to preserve the literal meaning of the string; that is: no special characters inside the string will be interpreted as special. - exception is the actual ' character which needs to be escaped if it is present in the string (examples are available in section 5.1 of the above guide)

We use double quotes (") to allow the interpreter to interpret special characters inside the string as special. Examples of special characters:

• \$ - references a variable value
• () and ` - used to tell the interpreter to execute a function/command,
more

Stats

Asked: 2016-01-07 14:10:18 -0500

Seen: 105 times

Last updated: Jan 07 '16