![](/img/trans.png)
[英]How can I get a return code from an ssh command inside a bash function, that is sourced inside another script?
[英]How can I get the return code for a command which ran via ssh and not the ssh command itself?
我正在尝试编写bash脚本,其中的第一步是检查远程主机中文件的存在以及该文件是否可执行。 这听起来像是test
命令的工作,但是我必须在它ssh
加上ssh
。 像这样:
$(ssh user@box 'test -x /path/thefile >/dev/null 2>&1; $?')
除了上述以外,似乎还没有工作来向我返回远程文件是否存在并且是否可执行...我该怎么做?
使用$()
语法时,您将获得命令的输出,而不是结果代码。 您可以这样做:
if ssh user@box 'test -x /path/thefile'; then
echo "It exists"
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.