Bash:使用多个可选标志调用脚本 - 它总是选择第一个并忽略其他

问题描述

我有一个 bash 方法:

  SUITE=''
  FILTER=''
  COVERAGE=''
  COVERAGE_REPORT_PATH="tests/Report"

  while getopts :s:f:c: flag # do not remove first colon as it makes flags optional
  do
      case "${flag}" in
          s) SUITE="--testsuite=${OPTARG}";;
          f) FILTER="--filter=${OPTARG}";;
          c) COVERAGE="--coverage-html ${COVERAGE_REPORT_PATH}";;
      esac
  done

  echo "docker exec -it my_api_1 ./vendor/bin/phpunit ${SUITE} ${FILTER} ${COVERAGE}";

当我运行它时:./local.sh phpunit -s Unit 它打印:

docker exec -it my_api_1 ./vendor/bin/phpunit --testsuite=Unit

当我运行它时:./local.sh phpunit -f MyClass 它打印:

docker exec -it my_api_1 ./vendor/bin/phpunit --filter=MyClass

但是当我使用两个标志运行它时:./local.sh phpunit -s Unit -f MyClass 它只打印第一个:

docker exec -it my_api_1 ./vendor/bin/phpunit --testsuite=Unit

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)