Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

difference between ' and "

Status
Not open for further replies.

ArmenD

Programmer
Feb 3, 2005
101
US
for the life of me, I have seen a bizillion times ' and " used in command line and scripting.

Would someone plz in human terms explain what the difference is between ' and ". When do we use which?

thanks in advnace,
 
Bash info page said:
Enclosing characters in single quotes (`'') preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

Enclosing characters in double quotes (`"') preserves the literal value of all characters within the quotes, with the exception of `$', ``', and `\'. The characters `$' and ``' retain their special meaning within double quotes (*note Shell Expansions::). The backslash retains its special meaning only when followed by one of the following characters: `$', ``', `"', `\', or `newline'. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash.

The special parameters `*' and `@' have special meaning when in double quotes (*note Shell Parameter Expansion::).


In human terms, double quotes will allow you to include whitespace in a token, and will inhibit something like a shell glob, but still allows for parameter expansion (via $) and command substitution (via `) unless you backslash-quote those two characters.

Single quotes are more of an "absolute" quote. No expansion occurs whatsoever in single quotes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top