I know exec is for executing a program in current process as quoted down from here
exec replaces the current program in the current process, without forking a new process. It is not something you would use in every script you write, but it comes in handy on occasion.
I'm looking at a bash script a line of which I can't understand exactly.
#!/bin/bash
LOG="log.txt"
exec &> >(tee -a "$LOG")
echo Logging output to "$LOG"
Here, exec doesn't have any program name to run. what does it mean? and it seems to be capturing the execution output to a log file. I would understand if it was exec program |& tee log.txt
but here, I cannot understand exec &> >(tee -a log.txt)
. why another >
after &>
?
What's the meaning of the line? (I know -a option is for appending and &>
is for redirecting including stderr)
EDIT : after I selected the solution, I found the exec &> >(tee -a "$LOG")
works when it is bash shell(not sh). So I modified the initial #!/bin/sh
to #!/bin/bash
. But exec &>> "$LOG"
works both for bash and sh.