批量 运行 的 shell 具有传递值的脚本

batch run of shell sript with passing values

我有一个 shell 脚本 (test.sh),它有一些参数要在 linux 执行期间传递。例如,

# sh test.sh        #My script
Choose model name
0:ESM 1:WED 2:PWD
1                   #I need to choose one from the above
Choose time period
0:2050 1:2080 2:2100
2                   #I need to choose one from the above
Downloading WED data for 2100    #download started
....

我正在寻找执行上述示例的 test.sh 的命令。我试过

sh test.sh > & out &

不问我就结束了

我猜您正在寻找一种以批处理方式将输入传递给脚本的方法。管它:

{ echo 1; echo 2; } | sh test.sh

或者,我有时用 printf "%s\n" 来做,这不需要为多行输入做 { } 大括号。

printf "%s\n" 1 2 "another arg" "etc.." | sh test.sh

在命令行给出参数,使用变量</code>、<code>等来使用

./test.sh arg1 arg2 > out