目前,我有一些标志-x
,以及其他一些标志:
while getopts abcx opt; do
case $opt in
a) a=true; ;;
b) b=true; ;;
c) c=true; ;;
x) x=true; ;;
esac
done
但是,我想这样做,以便添加x
会增加标志的级别。我已经在v
上看到过冗长的用法,而额外的v则增加了详细程度。如何在Bash脚本中检测到此情况?
分析解答
I want to make it so that adding an
x
will increase the level of the flag.
使用计数器:
unset a b c x
while getopts abcx opt; do
case $opt in
a) a=true; ;;
b) b=true; ;;
c) c=true; ;;
x) ((x++)); ;;
esac
done
echo "x=$x"
然后将其用作:
bash optscript.sh -abcxxx
x=3