LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why is my shell script giving me - syntax error near unexpected token 'enterInfo() (http://www.linuxquestions.org/questions/linux-newbie-8/why-is-my-shell-script-giving-me-syntax-error-near-unexpected-token-enterinfo-763931/)

chisunum 10-23-2009 06:33 AM

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

fusion1275 10-23-2009 07:38 AM

You can always start by defining what shell to use. I dont think
Quote:

#!
will work.

Just a good starting point.

bigrigdriver 10-23-2009 07:42 AM

if you are using the bash shell, #! should be #!/bin/bash

lutusp 10-23-2009 04:37 PM

Quote:

Originally Posted by chisunum (Post 3729643)
[-- snip --]

  • 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:
  1. Write a script consisting of one line.
  2. 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.
  3. Add one more line to your script and repeat step(2).
  4. Do not ever write hundreds of lines of code before establishing that you can write one line.
  5. 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.


All times are GMT -5. The time now is 03:00 AM.