Skip to content

Instantly share code, notes, and snippets.

@jmdeldin
Created July 24, 2015 22:02
Show Gist options
  • Save jmdeldin/f1e115c7a1e3d8bf8c44 to your computer and use it in GitHub Desktop.
Save jmdeldin/f1e115c7a1e3d8bf8c44 to your computer and use it in GitHub Desktop.
Using file descriptor 3
#! /bin/sh
echo "$0 [FILE] -- print a message to STDOUT or FILE" >&2
if [ -z $1 ]; then
exec 3>&1 # stdout
else
exec 3>"$1" # file
fi
echo hello this is dog >&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment