我的脚本使用的参数是我的两倍:
第一次使用以下代码,以确保没有我不想要的参数(我只考虑 arg1:arg2:arg3)
PARAM=$@
while [ "$#" -gt "0" ]; do
case $1 in
arg1)
shift2
;;
arg2)
shift
;;
arg3)
shift
;;
*)
echo "Usage : ./test.sh arg1 <VAL1> <VAL2> [arg2] [arg3]"
exit 2
;;
esac
shift
done
我想重新解析这些参数,并能够在我得到 arg1 时得到以下两个参数,所以我从这样的事情开始:
for command in $PARAM
do
case $command in
arg1)
shift
VALUE1=$command
shift
VALUE2=$command
exec_arg1
;;
esac
shift
但是在使用“shift”时,我得到了错误shift: can't shift that many
shebang 是“#!/bin/sh”,我正在寻找一个无需使用 bash 的 shebang 的解决方案(即“#!/bin/bash”)