Sample Header Ad - 728x90

How to stop redirection via exec

3 votes
1 answer
266 views
I want to redirect some output of a script to a file.
REDIRECT_FILE="foo.txt"

echo to console

# starting redirect
exec > $REDIRECT_FILE

echo to file
echo ...
echo ...

# stop redirect
exec >&-

echo end of script
"end of script" should be written to stdout. But instead there is a "Bad file descriptor" error message. exec 1>&- does not work too. What is the correct term to stop the redirection?
Asked by Andy A. (227 rep)
Nov 20, 2023, 01:34 PM
Last activity: Nov 20, 2023, 02:51 PM