summaryrefslogtreecommitdiffhomepage
path: root/tests/zash/getopts-edge.sh
blob: 24511db1ef93e2969ce2397324336ab0e2c5c81a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# getopts.
parse() {
    OPTIND=1
    while getopts ":ab:c" o "$@"; do
        case $o in
        a) echo "a" ;;
        b) echo "b=$OPTARG" ;;
        c) echo "c" ;;
        :) echo "missing arg for $OPTARG" ;;
        \?) echo "unknown $OPTARG" ;;
        esac
    done
    shift $((OPTIND - 1))
    echo "rest: $*"
}
parse -a -b x y z
parse -abval -c
parse -ac -- -b
parse -x -a
parse -b
parse -
parse
parse -b ''
loud() {
    OPTIND=1
    while getopts "ab:" o "$@"; do echo "o=$o OPTARG=${OPTARG-unset}"; done
}
loud -z 2>&1 | sed 's/^.*getopts/getopts/'
loud -b 2>&1 | sed 's/^.*getopts/getopts/'
set -- -a -b arg file
while getopts ab: o; do echo "$o ${OPTARG-}"; done; echo "OPTIND=$OPTIND"
getopts a o -q 2>/dev/null; echo "end status=$? o=$o"