https://github.com/k4n4t4/opt_parser
option parser in shell script
https://github.com/k4n4t4/opt_parser
shellscript
Last synced: 8 months ago
JSON representation
option parser in shell script
- Host: GitHub
- URL: https://github.com/k4n4t4/opt_parser
- Owner: k4n4t4
- License: cc0-1.0
- Created: 2025-04-12T05:26:43.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-29T06:33:26.000Z (about 1 year ago)
- Last Synced: 2025-04-29T07:40:06.939Z (about 1 year ago)
- Topics: shellscript
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# opt_parser
外部コマンドの呼び出しやサブシェルの起動をしていないのでたぶん高速です。
シェルスクリプトでコマンドのオプションを解析するのにつかえます。
結果は$RETに入ります。
## e.g.
### script.sh
~~~bash
qesc() {
: Omitted for brevity
}
opt_parser_get_arg_count() {
: Omitted for brevity
}
opt_parser() {
: Omitted for brevity
}
opt_parser p:1 params:3 -- "$@"
eval "set -- $RET"
while [ $# -gt 0 ]; do
case "$1" in
( -- )
shift
break
;;
( -a )
echo "option a"
shift
;;
( -b )
echo "option b"
shift
;;
( -p )
echo "option p"
shift
echo " $1"
shift
;;
( --abc )
echo "option abc"
shift
;;
( --params )
echo "option params"
shift
echo " $1"
echo " $2"
echo " $3"
shift 3
;;
esac
done
~~~
### command
`./script.sh -ab -p 123 --abc --params A B C`
### output
~~~
option a
option b
option p
123
option abc
option params
A
B
C
~~~