Unix Shell Script to prompt customer for name etc

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    How do I create a shell script called 'custinfo' to prompt a customer to enter and display back the following: name, age, address, phone number, product, price range.

Thanks

  1. Relevant commands, code, scripts, algorithms:

none

  1. The attempts at a solution (include all code and scripts):

echo "Enter your name:> \c"
read name

echo "enter your age:> \c"
read age

echo "enter address:> \c"
read address

echo "enter phone number:> \c"
read phone number

echo

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    I explained to a moderator yesterday that I am teaching myself unix.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

You're on the right track. You cannot use a variable that consists of two words.

read phone number

puts the answer in the variable "phone" or the part before the first whitespace in the variable "phone" and the remainder in the variable "number".

When someone enters the information, it should not be lost when the script terminates. So you will have to write the information on harddisk in just a plain text file. Best would be to use some symbol as separator to keep the fields separated. One line will represent one data set of a customer.

DATFILE=./customer.dat

echo "Enter your name:> \c"
read name

echo "Enter....
....
...

echo "$name:$age:$address:$phone" >> $DATFILE

After you're done with it, cat the customer.dat to see it's contents.

Next step will be to think about how you will retrieve this info stored in that text file - there are several options how to do that. What field or string should be able to be searched for - how will the result be displayed etc. ie. should all infos be displayed or only some.

zaxxon asked:

Next step will be to think about how you will retrieve this info stored in that text file - there are several options how to do that. What field or string should be able to be searched for - how will the result be displayed etc. ie. should all infos be displayed or only some.

Reply:
Name, age and address should be displayed.

Don't expect a ready-to-go script. You have basically 2 kind of functions your script will do:

  1. Take input and write to a file
  2. Take a search pattern to retrieve information

So you will maybe have a little menue or something in the beginning, where the user can choose if data should be added or searched.
You could script that with a read command, presenting 3 options where the third would be to exit for example. This input can be checked out with case/esac statement.
I'd say you best try to write the script with all the hints we presented so far and when it is ok and works so far, we go for the data retrieve part. Else you would not learn much from all this.