i have written a small script in which i use exec command and redriect output to a file..after sometime i want to switch it off and redirect the output to screen..how to do it
exec >> /tmp/out.txt 2>&1
//set of statements
then i want to switch of these exec as the rest should get displayed in screen and not int out.txt file
The first line sends fd 1 and fd 2 into your file. After that first line, put the lines that need to output to your file. Then use my second line which restores fd 1 and fd 2 to what they were originally.
The first line saves fd 1 and 2 by copying then to fd 4 and 5. The second line copies them back. The construct "4>&-" closes fd 4.