私は次のようなケーススクリプトを持っています:
for i in "$@"; do
arg=( $@ )
case $i in
--string)
for ((i=0; i<${#arg[@]}; i++)) ; do
if [ "${arg[$i]}" == "--string" ] ; then
((i++))
STRING=${arg[$i]}
fi
done
;;
*)
print_help
exit
;;
esac
done
./test --some_command --string pattern ; を実行すると ヘルプ オプションを出力します。文字列に *) オプションを指定せずに ./test --some_command --string pattern を実行すると、機能します。
これを修正する方法を教えてください。
もう一つの例 :
#!/bin/bash
test(){
echo i am testing this now
}
print_help()
{
echo help
}
for i in "$@"; do
arg=( $@ )
case $i in
--string)
for ((i=0; i<${#arg[@]}; i++)) ; do
if [ "${arg[$i]}" == "--string" ] ; then
((i++))
STRING=${arg[$i]}
fi
done
echo $STRING
;;
--test)
test
;;
*)
print_help
exit
;;
esac
done
./test --string pattern --test を実行すると。パターンヘルプを出力します