我有一个bash脚本,其中包含一些如下所示的函数:
my_functions.sh:
do_remote_command () {
ssh user@hostname "./runScript.sh $var1 $var2"
}
我正在通过另一个脚本调用此函数,该脚本正如上面所示:
#!/bin/bash
source my_functions.sh
do_remote_command
我想从./runScript.sh
获取返回码。我该如何说,"给我底层命令的返回码"?
答案 0 :(得分:0)
将my_functions.sh修改为
do_remote_command () {
ssh user@hostname "./runScript.sh $var1 $var2"
return $?
}
...并且新脚本可以将返回值回显为
#!/bin/bash
source my_functions.sh
echo do_remote_command