Lab 17

Back Up Next

horizontal rule

Home
Lab 1
Lab 2
Lab 3
Lab 4
Lab 5
Lab 6
Lab 7
Lab 8
Lab 9
Lab 10
Lab 11
Lab 12
Lab 13
Lab 14
Lab 15
Lab 16
Lab 17
Lab 18
Lab 19
Lab 20

Lab 17

(Chapter 17)

 

 


 

Learning Objectives

  1. To learn the basic concept of shell scripting (programming) in C shell
  2. To learn how shell programs can be executed
  3. To learn what shell variables are and how to use them
  4. To learn how to pass command line arguments to a C shell script
  5. To learn the concept of command substitution and its use in C shell scripts
  6. To learn some fundamental coding principles and their use in C shell scripts
  7. To practice C shell scripting by writing a few small size scripts

Lab Work

  1. Log on to your UNIX system
  2. Stay in your home directory and run the set, env, and printenv commands to display shell variables. In the outputs of these commands, capture below the lines for the following variables: cwd, gid, group, home, history, path, prompt, shell, uid, HOME, PATH, TERM, SHELL, MAIL, PWD, USER, GROUP, EDITOR, and PROMPT.
  3. Add the following directories in your search path: your current directory and ~/bin. Show your work.
  4. What will be output if the shell script keyin_demo in Section 17.3.5 is execute and you give * as input each time you are prompted? Does the output make sense? Explain.
  5. Write a C shell script that takes an ordinary file as an argument and removes the file if its size is zero. Otherwise, the script displays file’s name, size, number of hard links, owner, and modify date (in this order) on one line. Your script must do appropriate exception handling. Show a few sample runs of your script.
  6. Write a C shell script that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script. Show a few sample runs of your script.
  7. What happens when you execute the following sequence of shell commands? Give appropriate explanation where needed.

a.  set name=date

b.  $name

c.  `$name`

 

  1. Write a C shell script that displays the following menu and prompts for one-character input to invoke a menu option, as shown.

1.      List all files in the present working directory

2.      Display today’s date and time

3.      Invoke a C shell script that takes login names of a few users as command line arguments and displays the pathnames for their home directories.

4.      Display whether a file is a ordinary file or a directory

5.      Create a backup copy of a file

6.      Start a telnet session

7.      Start an ftp session

8.      Exit

Option (c) requires that you ask the user for a list of login names. For options (d) and (e), prompt the user for file names before invoking a shell command/program. For options (f) and (g), prompt the user for a domain name (or IP address) before initiating a telnet or ftp session. The program should allow the user to try any option any number of times and should quit only when the user gives option (h) as input. Show a sample run of your script.

A good programming practice is to build code incrementally—that is, write code for one option, test it, and then go to the next option.

  1. Log out.

 

 


 

 

horizontal rule

Back to CS140U Homepage
This page was last modified September 26, 2004
wmorales@pcc.edu