Created
April 23, 2021 19:43
-
-
Save tokland/0d5fe8125789cf0058d7ae6b830b7b5d to your computer and use it in GitHub Desktop.
Show command output while redirecting stdout/stderr to files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Like tee, but redirect both stdout and stderr to different files. | |
# | |
# Example: exec_and_tee2 file-with-stdout.txt file-with-stderr.txt find / -maxdepth 1 -type d | |
exec_and_tee2() { | |
local stdout=$1 stderr=$2 | |
shift 2 | |
{ "$@" > >(tee "$stdout"); } 2> >(tee "$stderr") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment