write the code to lookup, add and remove phone entries from the phonebook text file . These are the code we use for the lookup, add and remove in the case statement.
write the code to lookup, add and remove phone
entries from the phonebook text file .
These are the code we use for the lookup, add and remove in the case statement.
(Lookup)
# Look someone up in the phone book
grep $1 phonebook
(add)
echo "$1 $2" >> phonebook
sort -o phonebook phonebook
(Remove)
grep -v "$1" phonebook > /tmp/phonebook
mv /tmp/phonebook phonebook
Write a complete Bash script which will accept up to three command-line arguments: the first one is either (lookup, add or remove), the second one is a name enclosed in single quotes and the third one (if doing an add) is a phone number enclosed in single quotes. Using a case statement to match on either lookup, add or remove, the script should then perform the requested operation. Again here, you should first check for null arguments before continuing with the rest of the script or requested operation. In addition, the person may not be in the phonebook for lookup or remove so, you need to account for this.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images