Last active
January 7, 2018 06:34
-
-
Save dduan/f0a7a3266203da9652865665eed520f4 to your computer and use it in GitHub Desktop.
Run any command and suppress its output to stdin and stderr, unless it returns an error code.
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
#!/usr/bin/env bash | |
# Run any command and suppress its output to stdin and stderr, unless it returns an error code. | |
OUTPUT=$(${@:1} 2>&1) | |
if [ $? -eq 0 ]; then | |
exit | |
fi | |
OLDLFS=$LFS | |
IFS=$'\n' | |
for l in $OUTPUT; do | |
echo $l; | |
done | |
LFS=$OLDLFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment