Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does this do: exec > > (command)

Tags:

bash

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. :)

like image 437
jm666 Avatar asked May 28 '11 11:05

jm666


People also ask

What does exec command do?

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.

What does exec do in shell?

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.

What is exec in find command?

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.


1 Answers

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

like image 155
evgeny Avatar answered Oct 07 '22 02:10

evgeny