Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A telephone directory, called teledir.txt, maintains records in the form name: number where number is of the form nnn-nnn-nnnn for example; John: 480-727-1007 Devise a
A telephone directory, called teledir.txt, maintains records in the form name: number where
number is of the form nnn-nnn-nnnn for example;
John: 480-727-1007
Devise a shell script that accepts one or two arguments that could be:
- the name or number. If it exists in the directory, then the line should be displayed.
- both. The entry is displayed if it exists and is added if it doesnt exist in the file.
You can follow the steps below (not the only way):
- Assign the pathname to the file teledir.txt to a variable, say, TELEDIR. For example, if it is in your home directory, youll need to assign $HOME/teledir.txt to the variable TELEDIR
- Check that one or two arguments are supplied using $# and the caseesac construct.
- If one or two arguments are supplied, do nothing
- otherwise, Indicate that the usage must be in the form scriptname [name number], then exit
- Using the $# and the caseesac construct,
- If one argument is supplied,
- If it starts with a digit, search it in the file. If it doesnt exist, echo that Number doesnt exist
- If it starts with a letter (lower or uppercase), search it in the file. If it doesnt exist, echo that Name doesnt exist
- If two arguments are supplied, set the search_pattern to be name: number, and search it in the file.
- If it is not found, echo Adding entry, and append to the file/variable.
- Otherwise, echo that Entry exists
- If one argument is supplied,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started