Home‎ > ‎CIS 98‎ > ‎

Lab 5: Using the Shell

The purpose of this lab is to use shell variables and to write a simple batch shell script.

Practice: Variable Substitution 

The shell has a host of pre-defined variables (uppercase letters), like TERM, PATH, and PS1, as well as user-defined variables that you make up. When parsing the command line, the shell will replace any variable names with their values if the variable is preceded with a $

Which of the following commands work as expected? What can you surmise about the shell's priorities from these examples?
  1. echo begin $TERM end
  2. echo begin$PATH end
  3. echo begin$TERMend
  4. FILE=output
  5. who > $FILE
  6. CMD=wc
  7. $CMD output
  8. who | $CMD
You do not have to turn in the answers to the above questions. You should be confident in your answers before you proceed to the assignment.

Shell Programming

Write a shell script called lookup that will print out the account information of the current user from the /etc/passwd files in the following format: 

$ lookup
Mike Matera
User ID: 205
Primary Group: 503
Home Directory: /home/mmatera
Login Shell: /bin/bash

Pay attention to the following:
  1. The name comes from field five of the appropriate record from /etc/passwd.
  2. The primary group name comes from field the 4th field of the /etc/passwd file.
  3. The home directory comes from field sixth of the /etc/passwd file.
  4. The login shell comes from field seventh of the /etc/passwd file.
Collect all your information into appropriately named variables, and then display them on the screen so the output looks like the example.


  • 15 points for correct execution
  • 5 points for the design and style of the script

Turn In 

Your completed script should be located in: