Trouble with Advanced Shell Programming

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Trouble with Advanced Shell Programming
# 1  
Old 07-17-2011
Error 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.


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

3. 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!

4. 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).
# 2  
Old 07-17-2011
I think the problem is just that you use - instead of ~
~ means home.
This User Gave Thanks to neutronscott For This Post:
# 3  
Old 07-17-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Trouble with Shell Script Compressing file

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: You will create a shell script that performs the following action: Use a parameter to pass a file that... (5 Replies)
Discussion started by: Luvs2drnk
5 Replies

2. Shell Programming and Scripting

Trouble understanding shell scripting (mostly wsname)

Am still learning Scripting and I come across a build command that I don't really understand if /local/bin/wsname 2>/dev/null; then base="`/local/bin/wsname`" export base fi if ; then /local/bin/wsname exit 1 fi WSNAME="$base"/ can some one in light me to what... (1 Reply)
Discussion started by: Wpgn
1 Replies

3. Shell Programming and Scripting

Tcsh Shell trouble

Need assistance in getting a solution for a TCSH shell environment variable . I read on internet that leading zeros as octal numbers and redhat doesnt supports octals but Solaris works on TCSH shell. Is there any way we can fix this . All my script has 08 or 09 $ @ x = 5 + 08 @: Badly formed... (8 Replies)
Discussion started by: ajayram_arya
8 Replies

4. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

5. Shell Programming and Scripting

Shell advanced syntax?

I am not an expert of shell scripting, but I can do some simple things. Now, I read a script written by others and I need some help from the experts of this forum. Please help me to understand what is going on in this cycle: if ; then ] && \ export... (25 Replies)
Discussion started by: alt
25 Replies

6. Shell Programming and Scripting

Advanced error handling in shell scripts

Hi all I've got a question regarding error handling in shell scripts. My background is mainly object oriented programming languages, but for a year or so I've been doing more and more (bash) shell scripting (which I quite enjoy by the way). To handle errors in my scripts I... (3 Replies)
Discussion started by: script_man
3 Replies

7. Shell Programming and Scripting

shell variables advanced

Hi all, i have more questions but its all about variables so lets begin 1st, is possible to list all variables ? Command env display only shell variables, but what if i declared another variable? Command set display more variables but not defined by me. 2nd, what difference is between set... (24 Replies)
Discussion started by: wakatana
24 Replies

8. Post Here to Contact Site Administrators and Moderators

Where can I download the VTC - Unix Shell Scripting Advanced complete video

Where can I download the VTC - Unix Shell Scripting Advanced complete video. I don't know in which thread I should post this question.Plz help me out, or just tell me the link in the reply to this post. Thanks in advance. (0 Replies)
Discussion started by: villain41
0 Replies

9. Shell Programming and Scripting

Having trouble writing a basic shell program

Hello. I'm trying to write a shell script that will take files that have .tar, .tar.gz, .tar.Z, .gz, .Z and .zip file extensions and uncompress and unarchive them. The script should be able to take multiple arguments. So far I can write a script using the case command that will do this but it will... (3 Replies)
Discussion started by: SeanWuzHere
3 Replies

10. Programming

advanced socket programming

hi every one my post is about socket programming i would know if anyone knows about send binary file in peer to peer connection. if you have any information about it plzzz contact me or reply my post thx SpY974 (2 Replies)
Discussion started by: SpY974
2 Replies
Login or Register to Ask a Question