Command Line Conditional Execution Exercise.

Because this is an exercise, you can keep the worksheet up in a browser window rather than printing it out. Or you may print it out so you can better think about the output.

You will create two sets of commands which will be run in various combinations using the different command line delimiters. See below for constructing these.

The first set, s1, s2, s3, s4, and s5 will print their name and issue a successful return code of 0 on completion.

The other set, f1, f2, f3, f4, and f5, will print their name and and issue a non-zero return code equal to the number portion of their name on completion.

You will be assigned a set of 20 5-command sequences which mix &&, ||, ;, and () between the commands.

Click here to get the list of command sequences. Print this out if desired. Because this is an exercise, feel free to enter a different number on the generator page for a different set of questions.

In a work directory on hopper/turing, create the two sets of commands and run each of the sequences.

You may use any Linux text editor, pico, vim, emacs. You can also create the files on a PC and sftp them up to your account.

For each of the success commands, s1, s2, s3, s4, and s5, copy the following bash shell script into a file. Make it executable.

If you want, you can create a single file and hard link the 4 additional names to the original file.

      #!/bin/bash
      echo $0
      exit 0

For each of the fail commands, f1, f2, f3, f4, and f5, copy the following bash shell script. If you want, you can create a single file and hard link the 4 additional names to the original file.

      #!/bin/bash
      echo $0
      rc=`echo $0 | cut -c4`
      exit $rc 
For each problem on the work sheet, first, see if you can predict which command will run. Remember, the 1st command always runs. Then enter the command sequence in hopper or turing as it is shown and run it.

As they run, each of the commands that actually run will print out their names. For each of the commands, indicate which ran by circling it on the worksheet and write the value of the exit status after the "echo $?" on the work sheet.