Skip to content
koalaman edited this page May 28, 2017 · 1 revision

This case is not specified by getopts.

Problematic code:

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

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

Rationale:

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.

Exceptions:

None.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally