I have got following simple shell script, in which I am trying to send STDERR & STDOUT to both screen and log it in a file(test.log). Also, while exiting I am trying to exit with appropriate exit codes.In this code, I would expect it to echo first message (within the block) and exit. But, it is echoing both the statements and always exit with 0.$ cat test.sh#!/bin/kshn_exitstatus=0{  n_exitstatus=1  echo Inside block : $n_exitstatus  exit $n_exitstatus}  2>&1 | tee -a test.logecho Before last exit : $n_exitstatusexit $n_exitstatus$ sh test.shInside block : 1Before last exit : 0$ echo $?0How to amend this script to exit just after echo'ing first statement (to be logged in both screen and file) ?
Shell script exit code and logging
linux;shell;logs;exit