Skip to content

Instantly share code, notes, and snippets.

@mike-bourgeous
Forked from nitrogenlogic/00_swap_stderr_moved.md
Created October 23, 2016 00:45
Show Gist options
  • Save mike-bourgeous/bd58056617e1922ecba72abc58de94fc to your computer and use it in GitHub Desktop.
Save mike-bourgeous/bd58056617e1922ecba72abc58de94fc to your computer and use it in GitHub Desktop.
Swap stdout and stderr, log stderr to a file (BASH)
#!/bin/bash
test() {
echo "Standard out"
echo "Standard error" >&2
}
tmpfile=`mktemp`
test 3>&1 4>&2 2>&3- 1>&4- | tee $tmpfile
cat $tmpfile
rm $tmpfile
# Result:
# Standard out
# Standard error
# Standard error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment