From a946b8ae68744d86a00e34252aec2b9b75f05242 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 28 May 2017 13:33:51 -0700 Subject: [PATCH] Created SC2214 (markdown) --- SC2214.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 SC2214.md diff --git a/SC2214.md b/SC2214.md new file mode 100644 index 0000000..23399d5 --- /dev/null +++ b/SC2214.md @@ -0,0 +1,38 @@ +## This case is not specified by getopts. + +### Problematic code: + +```sh +while getopts "vr" n +do + case "$n" in + v) echo "Verbose" ;; + r) echo "Recursive" ;; + n) echo "Dry-run" ;; + *) usage;; + esac +done +``` + +### Correct code: + +```sh +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. \ No newline at end of file