CSCI 241 - Homework 7:
Shell Scripting

Due by 11:59.59pm Friday, 22 Nov 2008

Introduction

For this assignment you will be creating a number of shell scripts.

mypath

Create a shell script called mypath that takes a set of zero or more program names as parameter. The script should list for each command whether that program exists (and can be run by the user) in each of the directories of the current PATH. Your output should be in the order specified by PATH.

% ./mypath view emacs 
/usr/bin/view: symbolic link to `vim'
/usr/public/bin/view: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), 
            for GNU/Linux 2.4.1, dynamically linked (uses shared libs), stripped
/usr/bin/emacs: sticky ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), 
           for GNU/Linux 2.6.16, dynamically linked (uses shared libs), stripped

You'll probably want to look over the man pages for file and sh for insight. The behavior is similar to a combination of which -a and file.

lsdir

Create a shell script lsdir that lists only subdirectories (i.e., not any sort of file) in a given directory. Much as with the command ls, your program should take an optional list of arguments that are the names of directories. If no arguments are present, list subdirectories in the current directory. If arguments are present, list subdirectories of each of those directories specified.

You'll want to look through the manpages of test and possibly ls. You'll also want to consider the shell builtin cd. Be sure to consider the possibility that a specified directory doesn't exist, or that there is a space in the name of a directory.

% ./lsdir /usr 
bin
include
lib
libexec
local
man
sbin
share
src
tmp
users

If bored, add in a -l option and have it work like the -l option from ls.

listmajors

The registrar provides the faculty with lists of majors, but it contains a lot of extraneous information. I want you to write a script called listmajors which takes a list of files on the command line and for each of them extracts the student information and prints out one line per student in the order "NAME CLASS ID_NUMBER".

Here is a sample file: majors.txt

If more than one file is specified, you should print a blank line, the name of the file followed by an underline of the same length on the next line, before the output for that file.

You'll want to look over grep, cut, and tr as possible tools to use in this script. You may need to extract each component one at a time.

handin

README

Create a file called README that contains

  1. Your name
  2. A description of the programs
  3. Any known bugs or incomplete functions
  4. Any interesting design decisions you'd like to share

Now you should clean up your folder (remove test case detritus, etc.) and handin your folder containing your scripts and README.

% cd ~/cs241
% handin -c 241 -a 7 hw7

% lshand

Grading

Here is what I am looking for in this assignment:


VI PoweredLast Modified: November 18, 2008 - Benjamin A. Kuperman