我怎样才能得到像下面这样的用户输入,我想在shell脚本中使用它来构建一个case条件?
./iwant2reload-worker.sh --target=cluster --cluster-name=abc
./iwant2reload-worker.sh --target=workernode --workernode-name=xyz
例如:如果user发出第一个命令,它需要运行程序a,如果user发出第二个命令,它需要运行程序b。
#!/bin/bash
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
--target)
TARGET=$VALUE
;;
--cluster-name)
CLUSTER_NAME=$VALUE
;;
--workernode-name)
WORKNODE_NAME=$VALUE
;;
*)
echo "ERROR: unknown parameter "$PARAM""
exit 1
;;
esac
shift
done
#==========================
if [ ${TARGET} = "cluster" ]
then
echo "Run programm A for ${TARGET} & ${CLUSTER_NAME}"
fi
if [ ${TARGET} = "workernode" ]
then
echo "Run programm B for ${TARGET} & ${WORKNODE_NAME}"
fi