From 8710b6501b0c3886d4884a0abfc726255a5712c9 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Mon, 28 Apr 2014 20:36:08 +0800 Subject: [PATCH] Better "exec 3>&1" comment "Copy stdout to fd 3" is confusing. Explain the intention behind `exec 3>&1`. Change-Id: Id19434121876e65a14c709beac26b9daf4a36a0a --- stack.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stack.sh b/stack.sh index 4a8cb90d61..19d47d64ae 100755 --- a/stack.sh +++ b/stack.sh @@ -543,10 +543,11 @@ if [[ -n "$LOGFILE" ]]; then # Redirect output according to config - # Copy stdout to fd 3 + # Set fd 3 to a copy of stdout. So we can set fd 1 without losing + # stdout later. exec 3>&1 if [[ "$VERBOSE" == "True" ]]; then - # Redirect stdout/stderr to tee to write the log file + # Set fd 1 and 2 to write the log file exec 1> >( awk -v logfile=${LOGFILE} ' /((set \+o$)|xtrace)/ { next } { @@ -559,7 +560,7 @@ if [[ -n "$LOGFILE" ]]; then print fflush("") }' ) 2>&1 - # Set up a second fd for output + # Set fd 6 to summary log file exec 6> >( tee "${SUMFILE}" ) else # Set fd 1 and 2 to primary logfile @@ -574,7 +575,8 @@ if [[ -n "$LOGFILE" ]]; then ln -sf $SUMFILE $LOGDIR/$LOGFILENAME.summary else # Set up output redirection without log files - # Copy stdout to fd 3 + # Set fd 3 to a copy of stdout. So we can set fd 1 without losing + # stdout later. exec 3>&1 if [[ "$VERBOSE" != "True" ]]; then # Throw away stdout and stderr