tags:

views:

637

answers:

8

My keyboard only has normal quotes, not the smart ones.

I have obversed that I need normal ones in cgi development and the backward ones in AWK/SED.

Is there any 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.

+5  A: 

Backquotes are used a lot in shell/awk/perl programming, and when doing documents in TeX. Other than that, you probably won't use them much.

Paul Tomblin
+1  A: 

Smart quotes are the devil.

Ryan Graham
+2  A: 

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 language 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 then pick the quote that gives you that behavior.

Bryan Oakley
Powershell at least treats smart quotes as regular quotes. So it does support them in that fashion. Only language I'm aware of that does though.
EBGreen
+15  A: 

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.

Brian Campbell
These are also interesting examples: echo rm File* - - - and - - - echo `rm File*` The latter one removed the files, while the former one shows you what to remove.
Masi
+2  A: 

Smart quotes are for beautiful typesetting. They have nothing to do with programming.

Edit: the quotes you do need.

  • Double quotes: " " they are used for literal strings in many languages
  • Single quotes: ' ' used for literal characters in some languages like C and for strings in languages like javascript and php. (For example if you need to print a string "foo", you could use '"foo"')
  • Back quotes: in UNIX shells, to indicate substitution of the standard output from one command into a line of text defining another command. For example echo `date` might execute echo Sat Mar 1 09:43:00 GMT 2008 and print Sat Mar 1 09:43:00 GMT 2008.
abababa22
1+: I like your examples.
Masi
+1  A: 

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.

vartec
+1  A: 

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.

KevinDTimm
A: 

$ /usr/games/fortune

Marco Mariani