# Close standard output file descriptorexec 1<&-# Close standard error file descriptorexec 2<&-
# Open standard output as $LOG_FILE file for read and write.exec 1<>$LOG_FILE
# Redirect standard error to standard outputexec 2>&1
echo "This line will appear in $LOG_FILE, not 'on screen'"
echo "Will end up in standard output (terminal) and /var/log/messages"
…如下:
$ ./my_scriptWill end up in standard output (terminal) and /var/log/messages
$ tail -n1 /var/log/messagesSep 23 15:54:03 wks056 my_script_tag[11644]: Will end up in standard output (terminal) and /var/log/messages