Bash script to capture error message and change exit status
Pretty nice job for someone new to bash.
I have a couple of tips though.



Instead of this:

# capture the exit status of the call to p4 unshelve
if [ $? -eq 0 ]
then
    flag0=0
else
    flag0=1
fi


You can write simply:

flag0=$?


It's not exactly the same, because the error code might not be 1, but we can make it work with this lazy way too, see below.



Similar to earlier, instead of this:

if [ "$std_err_output" = "$error_message" ]
then
   flag1=1
else
   flag1=0
fi


You can do simpler:

[ "$std_err_output" = "$error_message" ]
flag1=$?




Similarly, instead of this:

exit_status="expr $flag0 | $flag1"

exit "$($exit_status)"


You can benefit from the fact that the exit code of the script will be the exit code of the last command. So you can simply write:

[ $flag0 = 0 ] &amp;&amp; [ $flag1 = 0 ]




Lastly, I suggest to move the rm tmp_file higher, to get it done as soon as you no longer need that file. No need to keep it around any longer than necessary.