Skip to content

Files

Latest commit

 

History

History
40 lines (30 loc) · 719 Bytes

SC2213.md

File metadata and controls

40 lines (30 loc) · 719 Bytes

Pattern: Unhandled getopts flag

Issue: -

Description

You have a while getopts loop where the corresponding case statement fails to handle one of the flags.

Either add a case to handle the flag, or remove it from the getopts option string.

Example of incorrect code:

while getopts "vrn" n
do
  case "$n" in
    v) echo "Verbose" ;;
    r) echo "Recursive" ;;
    *) usage;;
  esac
done

Example of correct code:

while getopts "vrn" n
do
  case "$n" in
    v) echo "Verbose" ;;
    r) echo "Recursive" ;;
    n) echo "Dry-run" ;;    # -n handled here
    *) usage;;
  esac
done

Further Reading