COMP 266 Study Guide - Quiz Guide: Bourne Shell, Working Directory
1. Write shell scripts specified in problem 13 at the end of Chapter 16. Test these
scripts, and make sure that they work.
Write a Bourne shell script for Problem 16 in Chapter 15, but use functions to implement
the service code for various options.
Modify the script in the case_demo file in Section 15.6.6 so that it allows you to try any
number of options and quits only when you use the q option.
Ans:
#!/bin/sh
echo " Use one of the following options:"
echo " d or D: To display today's date and present time"
echo " l or L: To see the listing of files in your present working
directory"
echo " w or W: To see who's logged in"
echo " q or Q: To quit this program"
optiond(){
date
}
optionl(){
ls
}
optionw(){
who
}
optionq() {
exit 0
}
while true; do
echo "Enter your option and hit <Enter>: "
read option
case "$option" in
d|D) optiond
;;
l|L) optionl
;;
w|W) optionw
;;
q|Q) optionq
;;
*) echo "Invalid option: try again."
;;
esac
done
find more resources at oneclass.com
find more resources at oneclass.com