[prev] [index] [next]

Quoting (cont)

Single-quotes are useful to pass shell meta-characters in args: e.g.   grep 'S.*[0-9]+$' < myfile

Use double-quotes to

  • construct strings using the values of shell variables

    e.g.   "x=$x, y=$y"    like Java's    ("x=" + x + ", y=" + y)

  • prevent empty variables from "vanishing"

    e.g.   use   test "$x" = "abc"   rather than   test $x = "abc"   in case $x is empty

  • for values obtained from the command line or a user

    e.g.   use   test -f " $1"   rather than   test -f $1   in case
    $1 contains a path with spaces (e.g. C:/Program Files/app/data