Trouble with Advanced Shell Programming

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:

I am working on a hands on project. We are creating a script for a corporate phone list. The project I am working on right now is modifying the already typed out script to protect against duplicate phone numbers using a process called input validation. I keep getting an error...

I was suppose to create a "tmp" directory in my home dir as directed by the book...and I did this...mkdir /home/name/tmp

Used ls to verify the tmp dir was there...but...

I got this error while trying to test the script as directed by the book:
Corporate Phone List Additions
==============================

Phone Number: 219-555-4511

/home/name/source/phoneadd: line 33: -/tmp/temp: No such file or directory

The script and all other pertinent information is mentioned below.

  1. Relevant commands, code, scripts, algorithms:

In vi, I have added the following code:

trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
phonefile=~/source/corp_phones
looptest=y
while test "$looptest" = "y"
do
clear
tput cup 1 4; echo "Corporate Phone List Additions"
tput cup 2 4; echo "=============================="
tput cup 4 4; echo "Phone Number: "
tput cup 5 4; echo "Last Name : "
tput cup 6 4; echo "First Name : "
tput cup 7 4; echo "Middle Init : "
tput cup 8 4; echo "Dept # : "
tput cup 9 4; echo "Job Title : "
tput cup 10 4; echo "Date Hired : "
tput cup 12 4; echo "Add Another? (y)es or (q)uit: "
tput cup 4 18; read phonenum
if test $phonenum = "q"
then
clear; exit
fi
# Check to see if the phone number already exists
while grep "$phonenum" $phonefile > -/tmp/temp
do
tput cup 19 1 ; echo "This number has already been assigned to: "
tput cup 20 1 ; tr ':' ' ' < ~/tmp/temp
tput cup 21 1 ; echo "Press ENTER to continue... "
read prompt
tput cup 4 18 ; echo " "
tput cup 4 18 ; read phonenum
if test $phonenum = "q"
then
clear ; exit
fi
done
tput cup 5 18; read lname
while test "$lname" = "-"
do
tput cup 4 18 ; echo " "
tput cup 4 18 ; read phonenum
if test "$phonenum" = "q"
then
clear ; exit
fi

There is more code, but it is irrelevant in my question.. this line right here(line 33):
" while grep "$phonenum" $phonefile > -/tmp/temp"

I was suppose to create a "tmp" directory in my home dir as directed by the book...and I did this...mkdir /home/name/tmp

Used ls to verify the tmp dir was there...but...

I got this error while trying to test the script as directed by the book:
Corporate Phone List Additions
==============================

Phone Number: 219-555-4511

/home/name/source/phoneadd: line 33: -/tmp/temp: No such file or directory

I also created the temp dir inside the tmp dir...and still nothing is working.

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

Like I said before, I tried to create a tmp directory, and tested it. It didn't work. Then I added the temp directory inside of the tmp directory. I'm sure this is some CRAZY easy fix, but I'm just not seeing it right now, and I'm really frustrated about it. I hope I filled this out right...if you have anymore questions please feel free to ask! Thank you in advance for your help!

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Texas State Technical College, Waco TX, United States. John Washington
Unix Operating Systems ITSC 1307.1001

Also, I am using Guide to Unix Using Linux Chapter 7 Project 7-14

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).

I think the problem is just that you use - instead of ~
~ means home.

1 Like

TADA!!! That is it! Except that I am suppose to use the ~ and I accidentally used a - ....thank you so much for your help. I was going insane over that. I don't know how programmers do it.