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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-12-2003, 03:45 PM
|
#1
|
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:
|
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.
|
|
|
08-12-2003, 04:27 PM
|
#2
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
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.
|
|
|
08-12-2003, 07:31 PM
|
#3
|
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:
|
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! =)
|
|
|
08-12-2003, 07:53 PM
|
#4
|
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:
|
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.
|
|
|
08-15-2003, 01:33 AM
|
#5
|
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:
|
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.
|
|
|
All times are GMT -5. The time now is 10:53 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|