16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Unix</strong> Tools<br />

# loop until user selects exit<br />

while true ; do<br />

# display menu<br />

echo '<br />

Would you like to:<br />

1. Look someone up<br />

2. Add someone to <strong>the</strong> phone book<br />

3. Remove someone from <strong>the</strong> phone book<br />

4. Change an entry in <strong>the</strong> phone book<br />

5. Show all entries in phone book<br />

6. Quit<br />

Please select one of <strong>the</strong> above (1-6):\c'<br />

# read and process selection<br />

read choice<br />

echo<br />

case "$choice" in<br />

1 | l) echo "Enter name to look up: \c"<br />

read name<br />

if [ -z "$name" ]; <strong>the</strong>n<br />

echo "Lookup ignored"<br />

else<br />

rololu "$name"<br />

fi;;<br />

2 | a) roloadd ;;<br />

3 | r) echo "Enter name to remove: \c"<br />

read name<br />

if [ -z "$name" ]; <strong>the</strong>n<br />

echo "remove ignored"<br />

else<br />

roloremove "$name"<br />

fi;;<br />

4 | c) echo "Enter name to change: \c"<br />

read name<br />

if [ -z "$name" ]; <strong>the</strong>n<br />

echo "change ingored"<br />

else<br />

rolochange "$name"<br />

fi;;<br />

5 | s) roloshowall;;<br />

6 | q) exit 0;;<br />

*) echo "Bad choice\007";;<br />

esac<br />

done<br />

#!/bin/sh<br />

# @(#)rololu - look up someone in <strong>the</strong> phone book<br />

if [ "$#" -ne 1 ]; <strong>the</strong>n<br />

echo "Incorrect number of arguments"<br />

echo "usage: rololu name"<br />

exit 1<br />

fi<br />

name=$1<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!