我在文件中有一个bash脚本,如下所示nepleaks_upd.sh
,我希望以此运行./nepleaks_upd.sh bootstrap --branch off
。无法接受--branch
,但是它的作用是./nepleaks_upd.sh bootstrap -b off
。
usage() { echo "Usage: $0 [prepare | up | down] [-b <on/off>]" 1>&2; exit 1; }
case "$1" in
bootstrap)
while getopts ":b:" o; do
case "${o}" in
b)
b=${OPTARG}
if [ ${b} == "off" ]; then
echo "git clone https://github.com/iPrayag/dotfiles.git"
## logic
fi
;;
*)
echo ${o}
usage
;;
esac
done
shift $((OPTIND-1))
echo "option1 = ${o}"
echo "option2 = ${b}"
if [ -z "${b}" ]; then
usage
fi
;;
up)
echo "up"
##logic
;;
down)
echo "down"
##logic
;;
*)
echo "Usage: $0 {up | down} dev"
exit 1
;;
esac
没有first case .. in .... esac
,它就可以正常工作。随着case ... in ... esac
,它给出了空白选项-b
,
$ ./nepleaks_upd.sh bootstrap -b off
option1 = ?
option2 =
Usage: ./nepleaks_upd.sh [bootstrap | up | down] [-b <on/off>]
@unxnut它唱samething兄弟
—
prayagupd
“没有第一
—
斯科特
case .. in .... esac
,就可以正常工作” 是什么意思?您是说第5-25行./nepleaks_upd.sh -b off
正确解析吗?也许您需要一个shift
,所以getopts
不要在“ bootstrap
” 上窒息。
@Scott是的,这部分工作正常。
—
祈祷
$1
吗?