Foil 01 - Using subroutine calls to process a list

 1 #!/bin/sh
 2 #*********************************************************************
 3 # Processing objects by calling a subroutine                         *
 4 #*********************************************************************
 5 
 6 rmmk()
 7 {
 8 hdisk="$1"
 9 addr="$2"
10 scsi="$3"
11 
12 echo "\nprocessing hdisk$hdisk at SCSI address $addr on $scsi"
13 rmdev -dl hdisk$hdisk
14 mkdev -c disk -t $type -s scsi -p $scsi -w $addr,0 -l hdisk$hdisk
15 
16 } # End of subroutine rmmk
17 
18 type="4500mb16bitde"
19 
20 #Cmd hdisk  addr   scsi
21 rmmk  2      2    scsi2
22 #rmmk  4      0   vscsi1
23 rmmk  12     3   vscsi3                                            #01

This is an example of how automation of repeated operation can be accomplished using subroutine calls. The subroutine, a.k.a. function, can be treated like a command with a variety of operands passed. This syntax of the subroutine is simple to remember and implement.

As written this script must be edited for any changes in the commands or the list of subroutine calls.

One difference from external commands is that the environment variables are available to and can be modified by the subroutine.

  • Lines 6, 7, and 16 define the subroutine.
  • Lines 8-10 assign the passed arguments to variables with meaningful names.
  • Lines 12-14 are the commands to execute.
  • Lines 20-24 are calls to the subroutine and how they can be commented out. Just use the text editor to add the subroutine call to the front of each.

    Line one has the standard #!/bin/sh to invoke the Bourne shell. Later examples may not all include this to save space.

    Previous   Next   Index