这个问题与其他问题很接近 -我可以从使用 $(command) 启动的子 shell 中获取退出代码吗?
但是,我发现没有解决方案可以让我在使用 local 和 eval 时从子 shell 获取退出代码,如本例所示...
test() { > local WHY="$(eval "echo 'test'"; exit 3)"; echo $? > } test 0
exit subshell exit-status
exit ×1
exit-status ×1
subshell ×1