Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Menu-Driven Application Yonglei Tao. Problem Statement  Develop a script program that allows the user to create and maintain an email directory, called.

Similar presentations


Presentation on theme: "A Menu-Driven Application Yonglei Tao. Problem Statement  Develop a script program that allows the user to create and maintain an email directory, called."— Presentation transcript:

1 A Menu-Driven Application Yonglei Tao

2 Problem Statement  Develop a script program that allows the user to create and maintain an email directory, called mydirectory  data is organized as follows Yonglei Tao:taoy@gvsu.edu Joe Smith:smithj@gmail.com …

3 Introduction Screen tput clear tput cup 5 15 echo “An Email Directory Application” echo “ Press any key to continue … “ read

4 Main Screen while true do tput clear …# display menu options read choice case $choice in 1)./add ;; 2)./update;; 3)./search;; 4)./delete;; 5)./print;; 6) tput clear ; exit 0 ;; *)./error ;; esac done

5 Script add echo –n “Enter name: ” read name echo –n “Enter email address: ” read address echo “$name:$address” >> mydirectory

6 Script search – Version One echo “Enter name: \c” read target if grep –iq “$target” mydirectory then echo –n “email address is ” gawk –F: ‘$target { print $2}’ mydirectory else echo “email address of $target not found” fi exit 0

7 Script search – Version Two echo “Enter name: \c” read target grep –i “$target” mydirectory > temp if [ -s temp ] then OLD_IFS=”$IFS” IFS=”:” read name address < temp echo “email address is $address” IFS=”$OLD_IFS” else echo “email address of $target not found” fi exit 0

8 Script update echo “Enter name: “ read name echo “Enter new email address: “ read address grep –iv “$name” mydirectory > temp mv temp mydirectory echo “$name:$address” >> mydirectory # an alternative way grep –iv “$name” mydirectory > temp echo “$name:$address” >> temp cat temp | sort > mydirectory How to do script delete?

9 Script print-1 sort –f –d –t: mydirectory > temp1 OLD_IFS=”$IFS” while read name address do echo “Name: $name” >> temp2 echo “Email: $address” >> temp2 echo >> temp2 done < temp1 IFS=”$OLD_IFS” pg –c –p “Page %d: “ temp2 rm temp1 temp2

10 Script print-2 gawk –F: ‘{ printf “Name: %s \n Email: %s \n\n”, $1, $2, }’ mydirectory | less


Download ppt "A Menu-Driven Application Yonglei Tao. Problem Statement  Develop a script program that allows the user to create and maintain an email directory, called."

Similar presentations


Ads by Google