When does command substitution spawn more subshells than the same commands in isolation?

Update and caveat: This answer has a troubled past in that I confidently claimed things that turned out not to be true. I believe it has value in its current form, but please help me eliminate other inaccuracies (or convince me that it should be deleted altogether). I’ve substantially revised – and mostly gutted – … Read more

Get exit code from subshell through the pipes

By using $() you are (effectively) creating a subshell. Thus the PIPESTATUS instance you need to look at is only available inside your subshell (i.e. inside the $()), since environment variables do not propagate from child to parent processes. You could do something like this: OUT=$( wget -q “http://budueba.com/net” | tee -a “file.txt”; exit ${PIPESTATUS[0]} … Read more