Reputation: 141180
My keyboard only has normal quotes, not the smart ones.
I have observed that I need normal ones in CGI development and the backward ones in AWK/SED.
Is there a rule when I should use smart quotes, normal ones and backward ones?
Obviously, I need to edit my keyboard layout to get the smart quotes.
Upvotes: 2
Views: 2281
Reputation: 182782
Backticks are used a lot in shell, AWK, and Perl programming, and when doing documents in TeX. Other than that, you probably won't use them much.
Upvotes: 6
Reputation: 385980
As far as I know, no language requires (or necessarily even supports) "smart quotes" unless you are calling the backtick character, `, a smart quote. If that's the case, many languages support the backtick. For example, both Bash and Ruby use the backtick for command substitution.
To answer the question Is there any rule when I should use smart quotes and normal ones?, yes, there is a rule (again, assuming you mean the backtick when you say "smart quotes"). In most languages, different types of quoting give you different types of behavior. The rule is, learn what the behavior is for that particular language, and then pick the quote that gives you that behavior.
Upvotes: 3
Reputation: 332846
If you mean `
by smart quotes, then that is actually called "backquote". Smart quotes are when you type ' and ", but get ‘ and ’ or “ and ” automatically depending on the context. I'm not sure how you would use smart quotes in awk or sed.
In the shell, backquotes, such as `command`
, are used to evaluate a command and substitute the result of the command within them into the shell expression being evaluated; it can be used to compute and argument to another command, or to set a variable. For less ambiguity, you can instead use $(command)
, which makes a lot of quoting rules easier to work out.
In the shell, '
and "
are also different. "
is used for strings in which you want variable substitution and escape sequences. '
represents a string containing just the characters within the quotes, with not variable interpolation or escape sequences.
So, for example:
$ name=world
$ echo "Hello, $name"
Hello, world
$ echo 'Hello, $name'
Hello, $name
$ echo "Testing \\ escapes"
Testing \ escapes
$ echo 'Testing \\ escapes'
Testing \\ escapes
$ echo `ls`
example-file another-example
$ echo 'ls'
ls
$ echo "ls"
ls
Other scripting languages, such as Perl and Ruby, have similar rules, though there may be slight differences.
Upvotes: 17
Reputation: 14376
Just an FYI, another term for 'smart quotes' (which I have never heard of that before), is grave accent.
I think the rules have been laid out pretty clearly in previous answers.
Upvotes: 1
Reputation: 4512
Smart quotes are for beautiful typesetting. They have nothing to do with programming.
Edit: the quotes you do need.
'"foo"'
)echo
``date\
might execute echo Sat Mar 1 09:43:00 GMT 2008 and print Sat Mar 1 09:43:00 GMT 2008.Upvotes: 7
Reputation: 134601
Smart quotes is word processor feature. When you type "quote" it gets automatically replaced with “quote” or „quote”. I think you got your nomenclature wrong.
Upvotes: 1