如果我跑步
mapfile -t array_files < <(ssh -i key user@host "find / -name search -type f")
并将结果打印到$?中,即使命令失败,我也收到0。
答案 0 :(得分:3)
使用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
在脚本中,默认情况下,作业控件是禁用的。