1

I always do this when passing variable to command

mkdir -p "$dir_to_make"

are those quotes needed? I tried to google but didn't find much. I always write them, just interested if they are necessary.

graywolf
  • 901
  • 2
  • 8
  • 25
  • 3
    They are necessary if the filename has special characters. – 123 Jul 05 '16 at 13:29
  • so in general purpose script they are probably good idea? – graywolf Jul 05 '16 at 13:32
  • 1
    @Paladin Absolutely. Quote, unless you have a specific reason not to. Saves you from worrying about word splitting, glob expansions, and the contexts in which they take place. – Petr Skocik Jul 05 '16 at 13:33
  • Exactly what 123 and PSkocik are saying. If you do `A="mydir/My Photos"; mkdir -p $A` (i.e. without the quotes on `$A`) you will get three dirs instead of two: `./mydir`, `./mydir/My` and `./Photos`. – grochmal Jul 05 '16 at 13:46
  • See: http://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells – Eric Renouf Jul 05 '16 at 13:48

0 Answers0