Due by 11:59.59pm Friday, 22 Nov 2008
For this assignment you will be creating a number of shell scripts.
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.
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.
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.
Create a file called README that contains
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
Here is what I am looking for in this assignment:
Last Modified: November 18, 2008 - Benjamin A. Kuperman