0

Consider:

$ read -r a <<<$(echo "foo"; exit 1)
$ echo $?
0

this returns 0, when I really expect a 1. How can I extract the real exit code from the subshell?

Foo
  • 198
  • 7

1 Answers1

1

You'll need multiple steps:

output=$(echo "foo"; exit 1)
status=$?
read -r a <<<"$output"       # assuming the "real" code here is more complex
glenn jackman
  • 84,176
  • 15
  • 116
  • 168