next next up down toc toc mail

10.17.  Shellprogramming

A pipe is the communication channel between two commands.

% cat /etc/passwd
root:R5/nLbJ3VF78s:0:1:Operator:/:/bin/csh
bischof:cpEXB4L5d5qwg:106:11:Hans-Peter Bischof:/home/bischof:/bin/sh
tymann:AFDcMs32dgrEQ:103:11:Paul Tymann:/home/tymann:/bin/sh
backup:kmyEWtLi1VflI:120:11:Backup:/home/backup:/bin/sh
% cat file | cut -f5 -d: | sort 
Backup
Hans-Peter Bischof
Operator
Paul Tymann

One example:

 1      #!/bin/sh
 2      
 3      MINIMUM=3144
 4      rm -f Single/*.ps
 5      
 6      PWD=`pwd`
 7      
 8      DIR=`echo $PWD | cut -d/ -f4`
 9      case $DIR
10              in      221)    echo "Foundations of CS"
11                              TARGET=$HOME/public_html/$DIR
12              ;;      214)    echo "Fortran Course"
13                              TARGET=$HOME/public_html/$DIR
14              ;;      *)      echo "$PWD!"
15                              exit 1
16      esac
17      
18      rm -f $TARGET/*.ps
19      
20      i=0
21      while :
22      do
23              i=`expr $i + 1 `
24              if [ $i -lt 10 ]
25              then
26                      name="00$i"
27              else
28                      if [ $i -lt 100 ]
29                      then
30                              name="0$i"
31                      else
32                              name=$i
33                      fi
34              fi
35              echo "--- > " $name
36      
37              cat header c.[01][0-9]                  |       \
38                      soelim                          |       \
39                      nsp -l4 -c14 2>/dev/null        |       \
40                      gpic                            |       \
41                      tbl                             |       \
42                      geqn                            |       \
43                      groff -ms -n1 -o$i  2> /dev/null        > Single/$name.ps
44      
45              size=`ls -l  Single/$name.ps | awk '{ print $5 } '`
46              
47              if [ $size -lt $MINIMUM ]
48              then
49                      rm Single/$name.ps
50                      cp Single/*.ps $TARGET
51                      break
52              fi
53      done
54       # ...
55      
56      exit 0


back next up down toc toc mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 27/July/98 (12:14)