why is my shell script giving me - syntax error near unexpected token 'enterInfo()
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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.
why is my shell script giving me - syntax error near unexpected token 'enterInfo()
#!
enterInfo()
{
empID=10
while [ $empID -lt 5000000000000 ]
do
echo "ENTER EMPLOYEE DETAILS FOR WHICH EMPLOYEE ID IS: $empID"
echo
echo
echo
echo
echo -n "ENTER EMPLOYEE FIRST NAME:"
read fname
while true
do
if [ -z $fname ]
then
echo "EMPLOYEE FIRST NAME CANNOT BE BLANK."
continue
else
break
fi
done
echo -n "ENTER EMPLOYEE LAST NAME:"
read lname
while true
do
if [ -z $lname ]
then
echo "EMPLOYEE LAST NAME CANNOT BE BLANK."
continue
else
break
fi
done
echo -n "ENTER EMPLOYEE DATE OF BIRTH:"
read dob
while true
do
if [ -z $dob ]
then
echo "EMPLOYEE DATE OF BIRTH CANNOT BE BLANK."
continue
else
break
fi
done
echo -n "ENTER EMPLOYEE DATE OF JOINING:"
read doj
while true
do
if [ -z $doj ]
then
echo "EMPLOYEE DATE OF JOINING CANNOT BE BLANK."
continue
else
break
fi
done
echo -n "ENTER EMPLOYEE DEPARTMENT:"
read dept
while true
do
if [ -z $dept ]
then
echo "EMPLOYEE DEPARTMENT CANNOT BE BLANK."
continue
else
break
fi
done
echo -n "ENTER EMPLOYEE GRADE:"
read grade
while true
do
if [ -z $grade ]
then
echo "EMPLOYEE GRADE CANNOT BE BLANK."
continue
else
break
fi
done
typeset -i bsalary
echo -n "ENTER EMPLOYEE BASIC SALARY:"
read bsalary
while true
do
if [ -z $bsalary ]
then
echo "EMPLOYEE BASIC SALARY CANNOT BE BLANK."
continue
else
break
fi
done
typeset -i allow
typeset -i deduction
typeset -i gsalary
case ${grade} in
"SSK") allow=bsalary\*0.2
deduction=bsalary\*0.1
gsalary=$((bsalary+allow)) - deduction
"HSK") allow=bsalary\*0.2
deduction=bsalary\*0.12
gsalary=$((bsalary+allow)) - deduction
"SK") allow=bsalary\*0.2
deduction=bsalary\*0.13
gsalary=$((bsalary+allow)) - deduction
"SMSK") allow=bsalary\*0.2
deduction=bsalary\*0.15
gsalary=$((bsalary+allow)) - deduction
"UNSK") allow=bsalary\*0.18
deduction=bsalary\*0.15
gsalary=$((bsalary+allow)) - deduction
esac
echo -n "ENTER EMPLOYEE DATE OF RETIREMENT:"
read dor
while true
do
if [ -z $dor ]
then
echo "EMPLOYEE DATE OF RETIREMENT CANNOT BE BLANK."
continue
else
break
fi
done
echo "empID: fname: lname: dob: doj: dept: grade: bsalary: dor: gsalary" >> employeeMaster
done
return
}
enterInfo
Repost your script using the provided CODE tags, so it will indent properly. This assumes that the original has any indentation.
The error message you provide refers to your entire function enterInfo(), e.g. all of it. In other words, the error message has no value.
I tried running your script. The number of errors is too great to list in a finite-length post, so the original error message was right. It is fair to say that, to a first approximation, the script is all error. So here is my advice:
Write a script consisting of one line.
Test that one line and satisfy yourself that it does what you expected. Do not proceed to step (3) until that one line works as expected and that you understand why it works.
Add one more line to your script and repeat step(2).
Do not ever write hundreds of lines of code before establishing that you can write one line.
Learn what a subroutine is, and use this wonderful ideas as often as possible. An entire script that is a single subroutine, especially one that doesn't work, doesn't count.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.