I must have been napping in High School when my English teacher explained this, but when is it appropriate to use single quotes, versus double quotes, around a word or phrase in a sentence?
In the US, double quotes are used to indicate quoted material. Single quotes are used for quotes within quotes:
He said, “My boss said, ‘Put up or shut up.’”
In the UK, it’s often the opposite.
Double quotes are used for quoted material (duh), as well as sometimes around words when you’re talking about the word itself.
e.g. The word “itself” is interesting, because. . .
Single quotes are generally only used when you’re quoting someone who is quoting someone else. You use the single quotes inside the double quotes.
e.g. I was talking to Bill, and he said, “You’ll never guess what Susan told me. She said, ‘Jay likes to use packaging tape instead of duct tape!’ I couldn’t believe it.”
Also, if you’re in the newspaper industry, you generally never use double quotes in headlines. That’s our style, at least.
e.g. Chancellor to University: ‘You suck!’
Double quotes allow for the expansion of variables within a string. Single quotes do not.
Example:
> which “$EDITOR”
/usr/bin/emacs
> which ‘$EDITOR’
$EDITOR: Command not found.
You forgot a smiley. And that’s only for PHP (AFAIK), which is not English.
PERL, too…
The example shown looks like it was just a plain, ordinary, Unix-style, generic shell.
Single quotes are used for a gloss following a foreign word, e.g.
Arabic sihâqîyah ‘lesbian’
Double quotes define a null terminated string.
Care to explain the shell’s use of back-quotes?
NB: Quotation marks are NOT to be used to emphasize a word. Unfortunately this incorrect use is rampant.
They can be used to indicate irony, or the fact that the phrase inside quotes is not actually true:
My “friend” Mary was spreading hideous lies about me.
Then when quotes are incorrectly used for emphasis, you’re not sure what to think, as in this sign at the turkey farm near me:
Frozen or “Fresh” Turkey Available
Sorry, I got caught up in my rant…I guess you meant single vs. double quotes, not quotes in general.
Carry on!
What’s a back-quote? A tick-mark: (`)?
I’ve never used the tick-mark, but a quick Google groups search seems to indicate that it’s used to ignore newline characters in the input stream. So I guess if you needed to break a line in the middle of a quoted string for some reason, you could.
I don’t know how it affects variable expansion, though. Oh, and what if the variable has newlines? It seems like it’s something I’d just try to avoid – console windows are plenty wide (and widenable) these days.
That’s it. The text/command inside the back quotes is replaced by the results of that command.
wpsun:filelist=`ls *log`
wpsun:echo $filelist
float.log perth.log trace.log
I’ve never seen it used for anything outside a Unix shell. Has a tick-mark got an ordinary purpose?
They’re also sometimes used paired with regular single-quotes, with the ` opening a quote and the ’ closing it. I’ve especially seen this usage in legal documents seeking to avoid ambiguity about just what is and is not quoted.