Skip to main content
Commonmark migration
Source Link

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 1>&3
echo "now goes to normal stdout"
exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

Edit:

###Edit: IfIf you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 1>&3
echo "now goes to normal stdout"
exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 1>&3
echo "now goes to normal stdout"
exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

Edit:

If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3
added 53 characters in body
Source Link
bgStack15
  • 2.2k
  • 2
  • 18
  • 24

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 1>&3
echo "now goes to normal stdout"
exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 1>&3
echo "now goes to normal stdout"
exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3
added 144 characters in body
Source Link
bgStack15
  • 2.2k
  • 2
  • 18
  • 24

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

You could put this line earlier on in your script:

exec 3>&1

Then whenever you need to send something to go to stdout:

echo "this goes to stdout" 1>&3

Cleanup:

exec 3>&-  #to remove fd3

How it works is that you define a new file descriptor, 3, and it points to the same place stdout does. You then redirect stdout as needed, but fd3 stays the same as what it was (which is your terminal). When you're done, just remove fd3!

###Edit: If you want output to goto both your file and "classic stdout", do this:

echo "goes both places" | tee -a $OUTPUT_FILE 1>&3
Source Link
bgStack15
  • 2.2k
  • 2
  • 18
  • 24
Loading