Shell Programming Case Study #6


#!/bin/sh
# case study #6

# How remember where stdout is going
# redirect stdout somewhere else
# then restore stdout back to what it was

echo This goes to my initial stdout

exec 3>&1   # save stdout in file descriptor 3
exec > f1   # change stdout to file f1

echo This is line 2 which will go into file f1

exec 1>&3   # restore stdout to what it was before

echo This is line 3 which goes to my initial stdout