Skip to content

Instantly share code, notes, and snippets.

@nitrogenlogic
Last active October 23, 2016 00:46
Show Gist options
  • Save nitrogenlogic/8511187 to your computer and use it in GitHub Desktop.
Save nitrogenlogic/8511187 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