我正在创建一个bash脚本,该脚本将包装docker run命令,并传入所有参数。正在运行的docker cmd具有一个-e
参数,如下所示:
docker run --rm -it --name some_name -v $(pwd):/some_dir some_image some_command -e -r -t
但是,由于某些原因,bash脚本未传递-e
参数。
例如,我有以下test.sh
脚本。
#!/bin/bash
echo "Echoing the command arguments."
echo $@
-e
参数在第一个位置时不会传递给$@
。
$ ./test.sh -e -r -t
Echoing the command arguments.
-r -t
$ ./test.sh -r -e -t
Echoing the command arguments.
-r -e -t
最终,我希望能够按以下方式调用docker命令,只需将所有给定参数从bash脚本传递到docker命令。
docker run --rm -it --name some_name -v $(pwd):/some_dir some_image some_command $@
如果用户期望传递-e
参数并且未发生关联活动,这可能会使用户感到困惑。
是否有一种方法可以允许-e
参数通过?
答案 0 :(得分:7)
将测试更改为:
data want;
input id a_no a_t b_t diff ;
datalines;
1 1 3 5 2
1 2 6 10 4
2 1 2 5 3
2 2 9 10 1
3 1 7 . .
;
run;
...,您会看到#!/bin/bash
echo "Echoing the command arguments:"
printf ' - %q\n' "$@"
出现。
当给定字符串作为第一个参数时,符合POSIX的-e
实现将在输出上显示echo
。除非同时设置-e
和set -o posix
运行时选项,否则bash的实现不符合要求。