Skip to content
koalaman edited this page May 28, 2017 · 4 revisions

getopts specified -n, but it's not handled by this 'case'.

Problematic code:

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

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

Rationale:

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.

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