LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-12-2003, 03:45 PM   #1
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Rep: Reputation: 30
Scripting Problems


Once again, I'm stumped and in need of help. This time I have not been able to see if this script actually works in school, but I was told I needed to get it up and running.

The script file is designed to take basic information from a user, about a user, and add it to a file called phonebook.sh. This is the file's syntex:

#! /bin/sh
# Chris Jepson
# 08-12-03
# /mnt/floppy/corp/corp_phone <Corperate Phone Database>

while [ "$loopagain" = y ]

do
echo "Please enter the First Name of the user."
read FirstName

echo "Please enter the Last Name of the user."
read LastName

echo "Please enter the Street Address of the user."
read Address

echo "Please enter the City of the user."
read City

echo "Please enter the State of the user."
read State

echo "Please enter the ZIP Code of the user."
read Zip

echo "Please enter the Phone Number of the user."
read Phone

echo "Do you want to add another user?
read loopagain

if [ "$loopagain" != y ]
then
exit
else
echo "Incorrect choice, please try again."
fi
done

phonefile=~/corp/phonefile.sh

if [ "$loopagain" > " " ]

then
echo "$FirstName:$LastName:$Address:$City:$State:$Zip:$Phone >> $phonefile"
fi

___________________________________________________________
This is the out come.
___________________________________________________________
/mnt/floppy/corp > ls
corp_phone phonefile.sh
/mnt/floppy/corp > ./corp_phone
./corp_phone: line 46: unexpected EOF while looking for matching `"'
./corp_phone: line 48: syntax error: unexpected end of file
/mnt/floppy/corp >
___________________________________________________________
My asumption is I may need to add the use of the grep ultility to this. Any assistance is very helpful and apreicated. Thanks in advance.

Last edited by dolvmin; 08-12-2003 at 03:47 PM.
 
Old 08-12-2003, 04:27 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You just need to change:
echo "Do you want to add another user?

to:
echo "Do you want to add another user?"

Note the extra " - if you read the error it tells you that that is the problem and even the line it is on.
 
Old 08-12-2003, 07:31 PM   #3
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Oh man, lol That's bad!

But I'll tell you what threw me off. The line number where the error was at is line 46. That is no where near where I forgot the ". I'll give it a fix and see what happens. Wish me luck! =)
 
Old 08-12-2003, 07:53 PM   #4
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Alright, I added the " at the end, as instructed, and it resolved that error but gave me a new one. I quickly remembered about spaces and removed them. Now the program starts, which means I am half way done. Thank you very much for that input.

However, I got a new problem. The other half of this program is not running.

The program allowes my to enter input for each field. However, when the while/do statement is completed, it does not record the information in the file "phonefile.sh"

Here's the syntex:

#! /bin/sh
# Chris Jepson
# 08-12-03
# /mnt/floppy/corp/corp_phone <Corperate Phone Database>

while [ "$loopagain"=y ]

do
echo "Please enter the First Name of the user."
read FirstName

echo "Please enter the Last Name of the user."
read LastName

echo "Please enter the Street Address of the user."
read Address

echo "Please enter the City of the user."
read City

echo "Please enter the State of the user."
read State

echo "Please enter the ZIP Code of the user."
read Zip

echo "Please enter the Phone Number of the user."
read Phone

echo "Do you want to add another user?"
read loopagain

if [ "$loopagain"!=y ]
then
exit
else
echo "Incorrect choice, please try again."
fi
done

phonefile=~/corp/phonefile.sh

if [ "$loopagain">" " ]

then
echo "$FirstName:$LastName:$Address:$City:$State:$Zip:$Phone >> $phonefile"
fi
___________________________________________________________

I strongly believe the problem is here:

phonefile=~/corp/phonefile.sh

if [ "$loopagain">" " ]

then
echo "$FirstName:$LastName:$Address:$City:$State:$Zip:$Phone >> $phonefile"
fi

___________________________________________________________

This is what my instructor gave me. However, I can not figure out what I'm doing wrong. There is "NO ERROR". This is leading me to believe that the last echo statement might not be running the way I'm expecting it to run. Again, any help will be apreicated. Thanks in advance.
 
Old 08-15-2003, 01:33 AM   #5
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Talking

Well, I got my problem resolved. It's up and running.

I found out the problem was I put to much faith in my instructor. =)

After finding the error that was causing my script file to not complete, I tried a few things and found the if statement to be rather, anoying to use. So I switched it over to case statements and really began to customize it. I didn't add to much comments to it yet, something I will be sure to do in short time but, here's a good idea as to what it looks like:

#! /bin/sh
# Chris Jepson
# 08-12-03
# /mnt/floppy/corp/corp_phone <Corperate Phone Database>

clear

while [ "$loopagain"=y ]

do
echo -e "\033[0mPlease enter the First Name of the user.\033[1;34m"
read FirstName
clear

echo -e "\033[0mPlease enter the Last Name of the user.\033[1;34m"
read LastName
clear

echo -e "\033[0mPlease enter the Street Address of the user.\033[1;34m"
read Address
clear

echo -e "\033[0mPlease enter the City of the user.\033[1;34m"
read City
clear

echo -e "\033[0mPlease enter the State of the user.\033[1;34m"
read State
clear

echo -e "\033[0mPlease enter the ZIP Code of the user.\033[1;34m"
read Zip
clear

echo -e "\033[0mPlease enter the Phone Number of the user.\033[1;34m"
read Phone
clear

echo -e "\033[0mFirst Name - \033[1;31m$FirstName\033[0m"
echo -e "Last Name - \033[1;31m$LastName\033[0m"
echo -e "Address - \033[1;31m$Address\033[0m"
echo -e "City - \033[1;31m$City\033[0m"
echo -e "State - \033[1;31m$State\033[0m"
echo -e "Zip Code - \033[1;31m$Zip\033[0m"
echo -e "Phone Number - \033[1;31m$Phone\033[0m"
echo
echo -e "\033[0mIs this information correct? ( \033[1;34mY\033[0m = Yes \033[1;34mN\033[0m = No )"
echo
read loopagain || continue

case $loopagain in

[Yy])
echo -e "\033[0mDo you want to add another user? ( \033[1;34mY\033[0m = Yes \033[1;34mN\033[0m = No )"

read loopagain || continue

case $loopagain in

[Yy]) phonefile=/mnt/floppy/corp/phonefile.sh
echo "$FirstName:$LastName:$Address:$City:$State:$Zip:$Phone" >> $phonefile
clear;;

[Nn]) phonefile=/mnt/floppy/corp/phonefile.sh
echo "$FirstName:$LastName:$Address:$City:$State:$Zip:$Phone" >> $phonefile
clear
exit;;

*) echo -e "\033[5;31m INCORRECT OPTION, PLEASE TRY AGAIN.\033[0m"
read loopagain
clear;;

esac;;



[Nn]) clear;;


*) echo -e "\033[5;31m INCORRECT OPTION, PLEASE TRY AGAIN.\033[0m"
read loopagain
clear;;

esac


done

_____________________________________________________
The script does work and is actually rather nice. I also created a script file that can be used to view all information that is thrown in to the file phonefile.sh:

#! /bin/sh
# Chris Jepson
# 08-14-03
# view_corp

List=/mnt/floppy/corp/phonefile.sh

clear
tput cup 2 30; echo "Corperate Database Viewer"
tput cup 3 30; echo "_________________________"
tput cup 5 0;
awk -F: '{printf "%-30s\t%-30s\n%-30s\t%-30s\t%-30s\t%-10s\n%-10s\n\n", $1, $2, $3, $4, $5, $6, $7}' $List

loopagain=n

while [ "$loopagain"=n ]
do

clear
tput cup 2 30; echo -e "\033[1;34mPhone File View\033[0m"
tput cup 3 30; echo "_______________"
tput cup 5 0;
awk -F: '{printf "%-30s\t%-30s\n%-30s\t%-30s\t%-30s\t%-10s\n%-10s\n\n", $1, $2, $3, $4, $5, $6, $7}' $List




tput cup 48 0; echo -e "\033[1;35mDo you wish to quit?\033[0m ( \033[5;34mY\033[0m = Yes \033[5;34mN\033[0m = No )"
read loopagain || continue

case $loopagain in

[Yy]) exit;;

[Nn]) clear;;


*) echo -e "\033[5;31m INCORRECT OPTION, PLEASE TRY AGAIN.\033[0m"
read loopagain
clear;;

esac
done

____________________________________________________

It still needs a bit more work, alittle tweeking here and there, more of a personal interest then a required one. Yet, it works non-the-less. Hope you enjoy it. Thanks for the help.

Last edited by dolvmin; 08-15-2003 at 01:34 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripting Problems! herve2001 Linux - General 7 02-26-2005 09:57 PM
Scripting problems - I'm sure this should be easy! webamoeba Linux - Newbie 6 02-03-2004 10:58 AM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 04:34 PM
Shell Scripting problems (newbie) yawgmoth81 Programming 11 02-24-2003 03:31 AM
scripting problems.. imnna2 Linux - Newbie 2 04-02-2001 10:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration