【发布时间】:2016-10-14 16:28:43
【问题描述】:
我有几个相互调用的脚本。但是当我通过时
来自 buid-and-run-node.sh 的片段
OPTIND=1 # Reset getopts in case it was changed in a previous run
while getopts "hn:c:f:s:" opt; do
case "$opt" in
h)
usage
exit 1
;;
n)
container_name=$OPTARG
;;
c)
test_command=$OPTARG
;;
s)
src=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
$DIR/build-and-run.sh -n $container_name -c $test_command -s $src -f $DIR/../dockerfiles/dockerfile_node
来自 build-and-run.sh 的片段
OPTIND=1 # Reset getopts in case it was changed in a previous run
while getopts "hn:c:f:s:" opt; do
case "$opt" in
h)
usage
exit 1
;;
n)
container_name=$OPTARG
;;
c)
test_command=$OPTARG
;;
f)
dockerfile=$OPTARG
;;
s)
src=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
我这样称呼它
build-and-run-node.sh -n test-page-helper -s ./ -c 'scripts/npm-publish.sh -r test/test-helpers.git -b patch'
目的是 npm-publish.sh 应该使用 -r 和 -b 参数运行。但是,当我运行脚本时,我得到了
build-and-run.sh: illegal option -- r
这显然意味着使用 -r 的是 build-and-run 命令。我该如何避免这种情况?
【问题讨论】:
-
shellcheck.net 会自动为您捕捉到这一点,无需人工审核。