Skip to content

Instantly share code, notes, and snippets.

@dduan
Last active January 7, 2018 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dduan/f0a7a3266203da9652865665eed520f4 to your computer and use it in GitHub Desktop.
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.
#!/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