Question: UNIX Objective: Practicing Bash decision structure A telephone directory, called teledir.txt, maintains records in the form name: number where number is of the form nnn-nnn-nnnn

UNIX

UNIX Objective: Practicing Bash decision structure A telephone directory, called teledir.txt, maintains

Objective: Practicing Bash decision structure A telephone directory, called teledir.txt, maintains records in the form name: number where number is of the form nnn-nnn-nnnn Devise a shell script that accepts one or two arguments that could be: i)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 doesn't exist in the file ii) 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, you'll need to assign SHOME/teledir.txt to the variable TELEDIR Check that one or two arguments are supplied using $# and the case construct. 1. 2. esac a) If one or two arguments are supplied, do nothing b) otherwise, Indicate that the usage must be in the form scriptname [name numberl, then exit 3. Using the $# and the case esac construct, a) If one argument is supplied " If it starts with a digit, search it in the file. If it doesn't exist, echo that "Number doesn't exist" If it starts with a letter (lower or uppercase), search it in the file. If it doesn't exist, echo that "Name doesn't exist" b) 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!