I'm using exec
like this:
#!/bin/bash
exec > >(tee /tmp/mylog.log) 2>&1
bash -c 'sleep 12312' &
I want the output of the commands to be in a log file, and then I want to start a long running script, and completely detach it, without doing anything to its output.
But I've noticed that running a script with exec to redirect output to a file makes it continue running with the long-running script. For example, save the above script to a file /tmp/start.sh
, run it, ps aux
will show that /bin/bash /tmp/start.sh
is still running!
If I remove the exec line, however, it's working as expected.
So how do I "detach" exec stdout redirection and have the script die once it's over?