0

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?

CuriousGuy
  • 1,473
  • 3
  • 17
  • 39

1 Answers1

1

Add the following line after your tee command:

test ${PIPESTATUS[0]} -eq 0 || exit ${PIPESTATUS[0]}

Reference Link: https://stackoverflow.com/a/34386000/2357256

Community
  • 1
  • 1
Samarth
  • 557
  • 5
  • 13