传播的所有参数在bash shell脚本 [英] Propagate all arguments in a bash shell script
本文介绍了传播的所有参数在bash shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写一个非常简单的脚本调用另一个脚本,我需要的参数从我当前脚本传播到我执行脚本。
I am writing a very simple script that calls another script, and I need to propagate the parameters from my current script to the script I am executing.
例如,我的脚本名称为 foo.sh
键,通话 bar.sh
For instance, my script name is foo.sh
and calls bar.sh
foo.sh:
bar $1 $2 $3 $4
我怎样才能做到这一点没有明确指定每个参数?
How can I do this without explicitly specifying each parameter?
推荐答案
使用$ @
而不是简单的 $ @
如果你真的希望你的参数传递相同的。
Use "$@"
instead of plain $@
if you actually wish your parameters to be passed the same.
注意:
$ cat foo.sh
#!/bin/bash
baz.sh $@
$ cat bar.sh
#!/bin/bash
baz.sh "$@"
$ cat baz.sh
#!/bin/bash
echo Received: $1
echo Received: $2
echo Received: $3
echo Received: $4
$ ./foo.sh first second
Received: first
Received: second
Received:
Received:
$ ./foo.sh "one quoted arg"
Received: one
Received: quoted
Received: arg
Received:
$ ./bar.sh first second
Received: first
Received: second
Received:
Received:
$ ./bar.sh "one quoted arg"
Received: one quoted arg
Received:
Received:
Received:
这篇关于传播的所有参数在bash shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文