Bash 不捕获 ssh 错误 [重复]

2023-12-12

If I run

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

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


用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

在脚本中,作业控制默认处于禁用状态。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bash 不捕获 ssh 错误 [重复] 的相关文章

随机推荐