I saw here and here too the following construction:
exec > >(tee -a script.log)
I know what the tee command is, and the (command...) usually means execute the command
in a subshell, and exec replaces the current shell with a program, like exec ls
, (but here there is no command) and additionally what is meant with the > >
?
Can anybody clarify this dark wizzardy?
exec >{space}> (command)
@Seth? :) Any pointer where i can read more about this magic would be appreciated. :)
The Linux exec command executes a Shell command without creating a new process. Instead, it replaces the currently open Shell operation. Depending on the command usage, exec has different behaviors and use cases.
On Unix-like operating systems, exec is a builtin command of the Bash shell. It lets you execute a command that completely replaces the current process. The current shell process is destroyed, and entirely replaced by the command you specify.
The best feature of the find command is its exec argument that allows the Linux user to carry out any command on the files that are found. In other words, actions can be performed on the files that are found.
It replaces the current bash
session with another, and writes the output of all commands to script.log
.
In that way, you can use your bash
shell normally, and you wouldn't see any difference (mostly), but all output is going to show up on your screen and in the script.log
file.
From exec manpages:
If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment.
The >(tee -a script.log)
magic creates a pipe, so instead of writing to a file like we would (with >> script.log
in this case), we write to the process tee -a script.log
, which does the same. For some reason unbeknown to me, using >>
does not work, but writing to the named pipe works. Source here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With