Shell Scripts

We often need to run programs repeatedly with different command line arguments.

For example, we may want to run program3.go repeatedly as follows:
./program3 2 3
./program3 3 3
./program3 4 3
./program3 2 4
./program3 3 4

. . .

In bash this is done using a shell script (created using an ordinary text editor.)

The following script is called script1.sh:

#!/bin/bash
go build program3.go
for (( j=3 ; j <= 5 ; j++ ))
do
   for (( i=2 ; i <= 4 ; i++ ))
   do
      ./program3 $i $j
   done
done

The first line of the script:#!/bin/bashtells your system to use the bash shell to execute the commands that follow.

Be sure to make the script executable with the command
chmod u+x script1.sh

The script is executed thus:
./script1.sh