Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何使用参数传递多个shell脚本_Bash_Shell - Fatal编程技术网

Bash 如何使用参数传递多个shell脚本

Bash 如何使用参数传递多个shell脚本,bash,shell,Bash,Shell,我有脚本a.sh和b.sh,其中我将ip作为参数传递 我试着把它当作 sh -x a.sh 172.19.57.21 & b.sh 172.19.57.21 & 但我只看到第一个脚本运行。使用在命令之间,如 sh -x a.sh 172.19.57.21 &; sh -x b.sh 172.19.57.21 & 运行sh-x a.sh 172.19.57.21和b.sh 172.19.57.21&: sh-xa.sh172.19.57.21是一个命令,&立即

我有脚本a.sh和b.sh,其中我将ip作为参数传递

我试着把它当作

sh -x a.sh 172.19.57.21 & b.sh 172.19.57.21 &

但我只看到第一个脚本运行。

使用
在命令之间,如

sh -x a.sh 172.19.57.21 &; sh -x b.sh 172.19.57.21 &

运行
sh-x a.sh 172.19.57.21和b.sh 172.19.57.21&

  • sh-xa.sh172.19.57.21
    是一个命令,
    &
    立即将其发送到后台

  • b.sh172.19.57.21
    是另一个命令,同样
    &
    将其置于后台

在我看来,问题在于脚本
b.sh
不可执行,并且由于您没有将其作为shell的参数运行(与
a.sh
不同),因此它在
路径
搜索中失败

您也可以将
b.sh
作为shell的参数运行,例如:

sh a.sh 172.19.57.21 & sh b.sh 172.19.57.21 &
或者,如果两个脚本都是可执行的,并且具有适当的shebang:

./a.sh 172.19.57.21 & ./b.sh 172.19.57.21 &

我建议使用一个包装器一次性获取参数IP地址,并从包装器中调用所需的脚本,类似于一个小函数:

wrapper() {
    /path/to/a.sh "$@" &
    /path/to/b.sh "$@" &
}
现在,您只需执行以下操作:

wrapper 172.19.57.21

之后不需要使用code>,请参阅bash(1)手册页中的“管道”一章。