~ubuntu-branches/ubuntu/trusty/abs-guide/trusty-proposed

« back to all changes in this revision

Viewing changes to abs/redir1.sh

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-06-03 10:57:27 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20120603105727-rm7frl4feikr2swm
Tags: 6.5-1
* New upstream release
* debian/watch
  - updated
* debian/abs-guide.lintian-overrides
  - updated for new upstream code
* debian/control
  - bump Standards-Version to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# Redirecting stdin using 'exec'.
3
 
 
4
 
 
5
 
exec 6<&0          # Link file descriptor #6 with stdin.
6
 
                   # Saves stdin.
7
 
 
8
 
exec < data-file   # stdin replaced by file "data-file"
9
 
 
10
 
read a1            # Reads first line of file "data-file".
11
 
read a2            # Reads second line of file "data-file."
12
 
 
13
 
echo
14
 
echo "Following lines read from file."
15
 
echo "-------------------------------"
16
 
echo $a1
17
 
echo $a2
18
 
 
19
 
echo; echo; echo
20
 
 
21
 
exec 0<&6 6<&-
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.
24
 
#
25
 
# <&6 6<&-    also works.
26
 
 
27
 
echo -n "Enter data  "
28
 
read b1  # Now "read" functions as expected, reading from normal stdin.
29
 
echo "Input read from stdin."
30
 
echo "----------------------"
31
 
echo "b1 = $b1"
32
 
 
33
 
echo
34
 
 
35
 
exit 0