Design Scripts  «Prev  Next»

Checking commands - Exercise

Test script commands on the Command Line

Objective: Use the command line to test commands as if they were executed within a script.

Exercise scoring

In this exercise you set up variables and use their values to execute a sort command, as you might within a script. This exercise is worth 3 points.


You should have an account set up on the DigitalThink Labs server or on a UNIX server at your site. Log in to this account so you see a UNIX command line prompt.


  1. Log in to your UNIX account so you are working at a command prompt.
  2. Start a Bourne command shell to simulate the shell script environment.
    % sh
  3. Set the value of the OPTIONS variable to -r to indicate reverse sorting order:
    $ OPTIONS="-r" 
  4. Set the value of the FILENAME variable to the /etc/passwd file (or another file whose contents you want to sort):
    $ FILENAME=/etc/passwd
  5. Execute the sort command using the variable values. Because of the variable values, this command will sort the /etc/password file in reverse order and display the result using the more command (which displays information a screenful at a time):
    $ sort $OPTIONS $FILENAME | more
  6. Press Enter to scroll down the output by one line or press q to exit the more command. Checking commands