Skip to content

Instantly share code, notes, and snippets.

@tokland
Created April 23, 2021 19:43
Show Gist options
  • Save tokland/0d5fe8125789cf0058d7ae6b830b7b5d to your computer and use it in GitHub Desktop.
Save tokland/0d5fe8125789cf0058d7ae6b830b7b5d to your computer and use it in GitHub Desktop.
Show command output while redirecting stdout/stderr to files
#!/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