Last active
November 21, 2019 14:46
-
-
Save marek-saji/095f59628e6d8f1405599cc270e63df3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
foo () | |
{ | |
echo stdout | |
echo stderr 1>&2 | |
return 1 | |
} | |
{ | |
{ | |
{ | |
# 1. Copy stdout to 3 and stderr to stdout (1) | |
thing 2>&1 1>&3 | |
# 2. Print exit status to 4 | |
echo $? 1>&4 | |
# 3. Our stdout is original stderr, so we can capture error messages | |
} | tee ./errors | |
# 4. Copy 1 (originbal stderr) to back 2 | |
# Copy 4 to 1, read it and produce exit status | |
} 4>&1 1>&2 | ( read -r STATUS; exit "$STATUS" ) | |
# 5. Copy 3 (original stdout) back to 1 | |
} 3>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment