Example script: ex11.sh


   1: #!/bin/sh
   2: 
   3: # Demonstrate reading a file line-by-line, using I/O
   4: # redirection in a compound command
   5: # Also test variable setting inside an implicit subshell.
   6: # Test this under sh and ksh and compare the output.
   7: 
   8: line="TEST"
   9: save=
  10: 
  11: if [ -z "$1" ]; then
  12:    echo "Usage: $0 filename"
  13: else
  14:    if [ -r $1 ]; then
  15:       while read line; do
  16:          echo "$line"
  17:          save=$line
  18:       done < $1
  19:    fi
  20: fi
  21: echo "End value of \$line is $line"
  22: echo "End value of \$save is $save"



  last modified 22/03/2012 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College