Skip to content

Instantly share code, notes, and snippets.

@zhaorui
Created January 31, 2018 01:45
Show Gist options
  • Save zhaorui/7afbf328491b2c536ba3491d7796aaaf to your computer and use it in GitHub Desktop.
Save zhaorui/7afbf328491b2c536ba3491d7796aaaf to your computer and use it in GitHub Desktop.
#!/bin/bash
# redirect STDOUT to a file (note the single > -- this will truncate /tmp/outfile)
exec 1> /tmp/outfile
echo Now all STDOUT from each subsiquent command will
echo be redirected to /tmp/outfile
echo but not STDERR >&2
# redirect STDERR to STDOUT and append (note the double >>) both to /tmp/outfile
exec 1>> /tmp/outfile 2>&1
echo now we get STDERR too >&2
# We can also turn off all output
echo 1>&-
echo 2>&-
echo Now you can\'t hear me!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment