Question: Please type your answer, thank you! :) No syntax errors please. The subject is UNIX A telephone directory, called teledir.txt, maintains records in the form

Please type your answer, thank you! :)

No syntax errors please.

The subject is UNIX

A telephone directory, called teledir.txt, maintains records in the form name: number where

number is of the form nnn-nnn-nnnn for example;

Chelsey: 480-727-1007

Devise a shell script that accepts one or two arguments that could be:

  1. the name or number. If it exists in the directory, then the line should be displayed.
  2. 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):

  1. 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
  2. Check that one or two arguments are supplied using $# and the caseesac construct.
    1. If one or two arguments are supplied, do nothing
    2. otherwise, Indicate that the usage must be in the form scriptname [name number], then exit
  3. Using the $# and the caseesac construct,
    1. If one argument is supplied,
      1. If it starts with a digit, search it in the file. If it doesnt exist, echo that Number doesnt exist
      2. If it starts with a letter (lower or uppercase), search it in the file. If it doesnt exist, echo that Name doesnt exist
    2. If two arguments are supplied, set the search_pattern to be name: number, and search it in the file.
      1. If it is not found, echo Adding entry, and append to the file/variable.
      2. 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!