From 10a0217ab0a886f3410903c2e84436b4965434df Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 28 May 2017 13:37:46 -0700 Subject: [PATCH] Created SC2213 (markdown) --- SC2213.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 SC2213.md diff --git a/SC2213.md b/SC2213.md new file mode 100644 index 0000000..5b5ac69 --- /dev/null +++ b/SC2213.md @@ -0,0 +1,37 @@ +## getopts specified -n, but it's not handled by this 'case'. + +### Problematic code: + +```sh +while getopts "vrn" n +do + case "$n" in + v) echo "Verbose" ;; + r) echo "Recursive" ;; + *) usage;; + esac +done +``` + +### Correct code: + +```sh +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. \ No newline at end of file