Created SC2213 (markdown)

koalaman
2017-05-28 13:37:46 -07:00
parent a946b8ae68
commit 10a0217ab0

37
SC2213.md Normal file

@@ -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.