首页 > 解决方案 > 以空格分隔的读取 Shell 脚本选项

问题描述

我有这个 shell 脚本:

for i in "$@"
do
case $i in
    -l=*|--ddloc=*)
    DDLOC="${i#*=}"
    shift # past argument=value
    ;;
    *)
          # unknown option
    ;;
esac
done

它工作正常,-x=y但我想成为这样-x y。这里需要进行哪些更改?

标签: shellsh

解决方案


for i in "$@"
do
case $i in
    -l=*|--ddloc=*)
    DDLOC="${i#*=}"
    shift # past argument=value
    ;;
    -l|--ddloc)
    shift # past argument
    DDLOC="$1"
    shift # past value
    ;;
    *)
          # unknown option
    ;;
esac
done

推荐阅读