Problem redirecting output to log file and console in bash script
0
votes
1
answer
2602
views
I have a shell script which sucessfully redirects all output to a log file and stdout (console) at the same time. However, when it exits it seems to wait for some user input from the keyboard (experimentally, any key seems to work)... So, I run the script, see the output, it exits and I have to hit e.g. the spacebar before the terminal prompt re-appears. Typing
echo $?
then gives the correct exit code.
The basics of the script are:
#!/bin/bash
LOG="./test.log"
rm -f $LOG
exec > >(tee $LOG) 2>&1
if [[ "$1" = "T" ]]; then
echo "twas true..."
exit 0
else
echo "twas false..."
exit 100
fi
Any help appreciated... not only do I not want to hit the spacebar but I would like to understand what is going on?
***Amendment***: it appears that I have to hit **enter** to get the terminal prompt back. From my limited experience using the *ps* command it would seem that my script has terminated and the *bash* shell is in the interruptible sleep state **S**. It would appear that maybe the terminal prompt output has been consumed or incorrectly redirected? I cannot see why...
Asked by Koorb Notsyor
(15 rep)
Sep 12, 2020, 04:56 PM
Last activity: Jul 31, 2025, 04:03 PM
Last activity: Jul 31, 2025, 04:03 PM