Difference between revisions of "Sample Scripts"
Jump to navigation
Jump to search
(Created page with "== Script using if== <pre> #!/bin/bash echo -e "This program adds entries to a family database file . \n" echo -e "Would you like to add an entry to the family database file?...") |
|||
Line 23: | Line 23: | ||
grep "$WORD" database | grep "$WORD" database | ||
fi | fi | ||
</pre> | |||
== Script using CASE== | |||
<pre> | |||
#!/bin/bash | |||
while true | |||
do | |||
clear | |||
echo -e "What would you like to do? | |||
Add and entry (a) | |||
Search an entry (s) | |||
Quit (q) | |||
Enter your choice (a/s/q)-->\c" | |||
read ANSWER | |||
case $ANSWER in | |||
a|A) echo -e "Please enter the name of the family member -->\c" | |||
read NAME | |||
echo -e "Please enter the family member's relation to you (i.e. mother) -->\c" | |||
read RELATION | |||
echo -e "Please enter the family member's telephone number -->\c" | |||
read PHONE | |||
echo -e "$NAME\t$RELATION\t$PHONE" >>database | |||
;; | |||
s|S) echo -e "What word would you like to look for?-->\c" | |||
read WORD | |||
grep "$WORD" database | |||
sleep 4 | |||
;; | |||
q|Q) exit | |||
;; | |||
*) echo "You must enter either the letter a or s" | |||
sleep 4 | |||
;; | |||
esac | |||
done | |||
</pre> | </pre> |
Revision as of 21:02, 19 April 2019
Script using if
#!/bin/bash echo -e "This program adds entries to a family database file . \n" echo -e "Would you like to add an entry to the family database file? \n" read ANSWER1 if [ $ANSWER1 = "y" -o $ANSWER1 = "Y" ] then echo -e "Please enter the name of the family member --> \c" read NAME echo -e "Please enter the family menber's relation to you (i.e. mother) -->\c" read RELATION echo -e "Please enter the family member's telephone number -->\c" read PHONE echo -e "$NAME\t$RELATION\t$PHONE">>database fi echo -e "Would you like to search an entry in the family databae file?\n" read ANSWER2 if [ $ANSWER2="y" -o $ANSWER2="Y" ] then echo -e "What word would you like to look for? -->\c" read WORD grep "$WORD" database fi
Script using CASE
#!/bin/bash while true do clear echo -e "What would you like to do? Add and entry (a) Search an entry (s) Quit (q) Enter your choice (a/s/q)-->\c" read ANSWER case $ANSWER in a|A) echo -e "Please enter the name of the family member -->\c" read NAME echo -e "Please enter the family member's relation to you (i.e. mother) -->\c" read RELATION echo -e "Please enter the family member's telephone number -->\c" read PHONE echo -e "$NAME\t$RELATION\t$PHONE" >>database ;; s|S) echo -e "What word would you like to look for?-->\c" read WORD grep "$WORD" database sleep 4 ;; q|Q) exit ;; *) echo "You must enter either the letter a or s" sleep 4 ;; esac done