I have the following script:
{
...
many commands and printing
...
if something goes wrong I do exit 1
} 2>&1 | tee test.log
But the problem is that the {} block is exiting and not the whole script.
How can I make the whole script exit?
Advertisement
Answer
Add the following line after your tee command:
test ${PIPESTATUS[0]} -eq 0 || exit ${PIPESTATUS[0]}
Reference Link: https://stackoverflow.com/a/34386000/2357256