Skip to content

Files

Latest commit

 

History

History
33 lines (22 loc) · 901 Bytes

SC2254.md

File metadata and controls

33 lines (22 loc) · 901 Bytes

Pattern: Use of unquoted variable in case branch pattern

Issue: -

Description

When unquoted variables and command expansions are used in case branch patterns, they will be interpreted as globs.

This can lead to some surprising behavior, such as case $x in $x) trigger;; esac not triggering in some cases, such as when x='Pride and Prejudice [1813].epub'.

To match the literal content of the variable or expansion, make sure to double quote the expansion.

Example of incorrect code:

case $input in
  -       ) echo "Reading from stdin..." ;;
  $output ) echo "Input should be different from output" ;;
esac

Example of correct code:

case $input in
  -         ) echo "Reading from stdin..." ;;
  "$output" ) echo "Input should be different from output" ;;
esac

Further Reading