Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When is it necessary to quote a command line argument?

share|improve this question

closed as unclear what you're asking by Tog, Dave M, Shekhar, Breakthrough, Mokubai Aug 3 '13 at 22:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Do you mean, "when is it necessary to place a command line argument in quotes"? – Tog Apr 30 '13 at 11:33

You need to quote when it otherwise would be interpreted differently from what you might intent by the shell.

A few examples:

You'd quote the string argument foo bar to prevent a program to interpret it as two arguments due to the space.

# results in two directories, 'foo' and 'bar'.
mkdir foo bar

# results in one directory named 'foo bar'
mkdir "foo bar"

# you could also escape the space to prevent interpretation as argument separator
mkdir foo\ bar

You also quote to prevent some special interpretation of your input. If the shell uses $ to indicate a variable name, foo$bar might get interpreted as foo if $baris emoty undefined, or even produce an error.


# create directory fooqux
mkdir foo$bar

# create directory foo$bar
mkdir 'foo$bar'

As a special case, e.g. in bash, you quote $@ (the current command's arguments) to make sure they're passed to another command quoted individually. See here for more information.

share|improve this answer
Always a good read: Quotes on Greg's Wiki and Quotes and escaping from the Bash Hackers Wiki. – slhck Apr 30 '13 at 9:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.