[英]How can I get a return code from an ssh command inside a bash function, that is sourced inside another script?
我有一个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
获取返回代码。 我怎么能说“给我底层命令的返回码”?
修改my_functions.sh为
do_remote_command () {
ssh user@hostname "./runScript.sh $var1 $var2"
return $?
}
...并且新脚本可以将返回值作为
#!/bin/bash
source my_functions.sh
echo do_remote_command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.