在 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 no_quotes.sh
#!/bin/bash
echo_args.sh $@
$ cat quotes.sh
#!/bin/bash
echo_args.sh "$@"
$ cat echo_args.sh
#!/bin/bash
echo Received: $1
echo Received: $2
echo Received: $3
echo Received: $4
$ ./no_quotes.sh first second
Received: first
Received: second
Received:
Received:
$ ./no_quotes.sh "one quoted arg"
Received: one
Received: quoted
Received: arg
Received:
$ ./quotes.sh first second
Received: first
Received: second
Received:
Received:
$ ./quotes.sh "one quoted arg"
Received: one quoted arg
Received:
Received:
Received:
这篇关于在 bash shell 脚本中传播所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文