Bash不能捕获ssh错误 [英] Bash don't capture ssh errors

查看:49
本文介绍了Bash不能捕获ssh错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我跑步

mapfile -t array_files < <(ssh -i key user@host "find / -name search -type f")

并将结果打印到$?中,即使命令失败,我也收到0.

and print the results in $?, I receive 0 even when the command fail.

推荐答案

使用bash.

# disable job control and enable lastpipe to run mapfile in current environment
set +m; shopt -s lastpipe

# feed array_files with the output of your ssh/find command
ssh ... | mapfile -t array_files

# returncode of first command in pipe (here ssh)
echo "${PIPESTATUS[0]}"

# content of array array_files
declare -p array_files

在脚本中,默认情况下,作业控件处于禁用状态.

In a script job control is disabled by default.

这篇关于Bash不能捕获ssh错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆