1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Created SC2214 (markdown)

koalaman 2017-05-28 13:33:51 -07:00
parent cdc39ff5bd
commit a946b8ae68

38
SC2214.md Normal file

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