bash

In "case $expression in" are double quotes necessary or not?


Using bash, in the case esac structure, are double quotes necessary in $expression:

case "$expression" in
    ...
esac

or not:

case $expression in
    ...
esac

?


Solution

  • No, quotes are generally not necessary.

    According to the manual (see Conditional Constructs):

    The word undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal (see Shell Parameter Expansion) before matching is attempted.

    Since pathname expansion and word splitting are not applied to word, the typical function of quotes to suppress those behaviors is redundant. The only potential benefit of quotes is to suppress tilde expansion.