Comment detail

起動オプションの解析 (Nested Flatten)

This comment is reply for 7605 emasaka: pure bashで内蔵コマンドgeto...(起動オプションの解析). Go to thread root.

#7614の訂正にしたがって簡略化してみます。

 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
#!/bin/bash
while getopts 'oqd:*' opt;do
    case "$opt" in
    o)  opt_o=ON ;;
    q)  opt_q=ON ;;
    d)  opt_d=$OPTARG
        [[ $opt_d == [012] ]] || exit 1
        ;;
    esac
done
shift $((OPTIND - 1))

[ -z "$opt_o" ] && exit 1
[ $# = 0 ] && exit 1

echo "[オプション情報]
o(output): ON
q(quote):  ${opt_q:-OFF}
d(debug):  ${opt_d:-}

[パラメータ情報]
指定数: $#"

i=0
for e in "$@";do
    echo "$((++i)): $e"
    shift
done

Index

Feed

Other

Link

Pathtraq

loading...