我是bash的新手。需要針對以下問題提出建議。在bash中解析的參數
所以,我想用這種方式
./myscript --bootstrap bootstrap.exe --vmmount ./vmmount --image /dev/sdb2 --target-exe installer.exe [--internal-exe] param1 param2 param3 ...
參數解析器我已經做執行腳本:
VMMOUNT=""
BOOTSTRAP=""
IMAGE_FILE=""
TARGET_EXE=""
INTERNAL_EXE=""
while : ; do
if [ "$1" = "--vmmount" ] ; then
[ -n "${VMMOUNT}" ] && usage
VMMOUNT="$2"
shift
shift
elif [ "$1" = "--bootstrap" ] ; then
[ -n "${BOOTSTRAP}" ] && usage
BOOTSTRAP="$2"
shift
shift
elif [ "$1" = "--image" ] ; then
[ -n "${IMAGE_FILE}" ] && usage
IMAGE_FILE="$2"
shift
shift
elif [ "$1" = "--target-exe" ] ; then
[ -n "${TARGET_EXE}" ] && usage
TARGET_EXE="$2"
shift
shift
elif [ "$1" = "--internal-exe" ] ; then
[ -n "${INTERNAL_EXE}" ] && usage
INTERNAL_EXE="true"
shift
shift
else
break
fi
done
my_method "${IMAGE_FILE}" "${VMMOUNT}" "${BOOTSTRAP}" "${TARGET_EXE}" "${INTERNAL_EXE}"
現在我在解析參數參數1混亂和參數2等等如何解析他們?我可以使用[email protected]
將參數作爲數組還是其他有效方式使用?
而不是所有'elif'語句,使用'case'。 – Barmar