Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 753 Bytes

SC2214.md

File metadata and controls

41 lines (31 loc) · 753 Bytes

Pattern: Redundant getopts flag

Issue: -

Description

You have a case statement in a while getopts loop that matches a flag that hasn't been provided in the getopts option string.

Either add the flag to the options list, or delete the case statement.

Example of incorrect code:

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

Example of correct code:

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

Further Reading