Bash getopts不在shell脚本上迭代

Bash getopts不在shell脚本上迭代,bash,sh,Bash,Sh,我在bash脚本上遇到getopts问题。特别是,下面的代码似乎不能使用超过1个参数 如果我这样做: ./script.sh - t template-name -m terminal-name 只有模板变量被填充,而如果我这样做 ./script.sh - m terminal-name -t template-name 只有末梢是化蛹的 while getopts ":m:t:r:" optname; do case "${optname}" in

我在bash脚本上遇到getopts问题。特别是,下面的代码似乎不能使用超过1个参数

如果我这样做:

./script.sh - t template-name -m terminal-name 
只有模板变量被填充,而如果我这样做

./script.sh - m terminal-name -t template-name
只有末梢是化蛹的

 while getopts ":m:t:r:" optname;
        do
          case "${optname}" in
            "m")
              terminal = $OPTARG
              ;;
            "t")
              echo "Using template: $OPTARG"
              template = "$(cat $OPTARG)"
              ;;
            "r")
              reboot="yes"
              tput setaf 1; echo "TERMINAL WILL BE REBOOTED WHEN DONE!!"
              ;;
            "?")
              echo "Unknown option $OPTARG"
              ;;
            ":")
              echo "No argument value for option $OPTARG"
              ;;
            *)
            # Should not occur
              echo "Unknown error while processing options"
              ;;
          esac
        done
    shift $((OPTIND-1))

我相信如果您在一段时间内使用getopts,您不需要轮班。

终端=$OPTARG
:删除
=
周围的空格!再也不会有这样的问题了。无论是
终端
还是
模板
都不会被分配到代码中,如图所示。谢谢大家!问题解决了移除空间的问题