Sunday 13 August 2017

Bash Exec in the Context of I/O Redirection

Cited from understanding bash “exec 1>&2” command

exec is a built-in Bash function, so it can have special behavior that an external program couldn't have. In particular, it has the special behavior that:

If COMMAND is not specified, any redirections take effect in the current shell.

This applies to any sort of redirection; you can also write, for example, any of these:

exec >tmp.txt
exec >>stdout.log 2>>stderr.log
exec 2>&1

No comments:

Post a Comment