Permalink
Please sign in to comment.
Browse files
Spec tests for the getopts builtin.
Alpine Linux uses this a lot.
- Loading branch information...
Showing
with
24 additions
and 0 deletions.
- +19 −0 spec/builtin-getopts.test.sh
- +5 −0 test/spec.sh
| @@ -0,0 +1,19 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Bash implements type -t. | ||
| # | ||
| # NOTE: Aliases don't work in batch mode! Interactive only. | ||
| ### Basic getopts invocation | ||
| set -- -h -c foo x y z | ||
| FLAG_h=0 | ||
| FLAG_c='' | ||
| while getopts "hc:" opt; do | ||
| case $opt in | ||
| h) FLAG_h=1 ;; | ||
| c) FLAG_c="$OPTARG" ;; | ||
| esac | ||
| done | ||
| shift $(( OPTIND - 1 )) | ||
| echo h=$FLAG_h c=$FLAG_c optind=$OPTIND argv=$@ | ||
| # stdout: h=1 c=foo optind=4 argv=x y z |
0 comments on commit
232d722