Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which is the correct way of handling arguments with spaces?

  • A.Use single quotes
  • B.Either single or double quotes
  • C.Use double quotes
  • D.There is no way of handling arguments with space

Answer: B

Correct answer: Either single or double quotes

The shell splits the command line on whitespace, so an argument containing a space must be quoted to arrive intact. Both quoting styles achieve that.

They differ in what else they do: double quotes still allow the shell to expand variables and command substitutions inside them, while single quotes suppress everything and pass the text literally. For an argument containing only spaces either works; where the text also contains $ or a backtick, single quotes are the safer choice.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.