2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-15 06:12:59 +00:00
cheat.sheets/sheets/exec

18 lines
552 B
Plaintext
Raw Normal View History

2017-06-14 08:56:21 +00:00
# exec
#
# Shell builtin command
2020-02-29 23:32:19 +00:00
# It can start a new process to replace the shell, without a new process
# creation. It can make redirections take effect in the current shell
2017-06-14 08:56:21 +00:00
2020-02-29 23:32:19 +00:00
# Redirect all STDOUT from within a script to the given file.
2017-06-14 08:56:21 +00:00
exec > foo.log
2020-02-29 23:32:19 +00:00
# Redirect all of both STDOUT & STDERR from within a script to the given file.
2017-06-14 08:56:21 +00:00
exec > foo.log 2>&1
2020-02-29 23:32:19 +00:00
# Or, if on bash(1), this syntax is also viable:
exec &> foo.log
2017-06-14 08:56:21 +00:00
2020-02-29 23:32:19 +00:00
# Copy output to a log file, allowing the outputs to still work as usual.
2017-06-14 08:56:21 +00:00
exec > >(tee -ia foo.log)
exec 2> >(tee -ia foo.log >&2)