我希望选项-h可以单独使用而不会累积任何其他选项,例如(-h -l)。我该怎么办?
case $1 in
-h)help;;
-f)aa;;
esac
case $2 in
-l)bb;;
esac
case $3 in
-p)cc;;
esac
感谢。
答案 0 :(得分:1)
示例代码
#!/bin/bash
while getopts "ha" opt; do
case $opt in
a)
echo "-a was triggered!" >&2
;;
h)
echo "-h was triggered!" >&2
;;
esac
done
测试用例
./example.bash -a -h
-a was triggered!
-h was triggered!