2
# Redirecting stdin using 'exec'.
5
exec 6<&0 # Link file descriptor #6 with stdin.
8
exec < data-file # stdin replaced by file "data-file"
10
read a1 # Reads first line of file "data-file".
11
read a2 # Reads second line of file "data-file."
14
echo "Following lines read from file."
15
echo "-------------------------------"
22
# Now restore stdin from fd #6, where it had been saved,
23
#+ and close fd #6 ( 6<&- ) to free it for other processes to use.
25
# <&6 6<&- also works.
28
read b1 # Now "read" functions as expected, reading from normal stdin.
29
echo "Input read from stdin."
30
echo "----------------------"