Code: Select all
somecommand | head -n 2Is there a way to do this and to test the exit status of "somecommand" rather than "head" (which will always be success even if somecommand fails) ?

Code: Select all
somecommand | head -n 2Code: Select all
foo="$(somecommand)"
rval=$?
echo $foo | head -n 2
Code: Select all
foo="$(somecommand)"
rval=$?
echo "$foo" | head -n 2

PIPESTATUS[0] (see man bash)humbletech99 wrote:When I do$? is always the exit status of the "head" command rather than that of "somecommand"Code: Select all
somecommand | head -n 2
Is there a way to do this and to test the exit status of "somecommand" rather than "head" (which will always be success even if somecommand fails) ?