1

I'm not sure why my if statement is not working. It prompts to enter Weekly Salary even if $EmployeeType is Commission or Hourly. Should I be using if statement for all instead of elif? I tried using all if statements but keep having error "syntax error near unexpected token "}"". Please kindly advice.

Output:

Enter Payroll of an employee 

Enter employee name: Mary
Mary is Hourly employee.

Enter Weekly Salary :




payroll_employee()
{

   echo
   echo "[Option: $input]"
   echo "Enter Payroll of an employee "
   echo
   echo -en "Enter employee name: "
   read Name

  #Retrieve current entry into individual fields                                                        
  line=`grep -i "$Name" $PAYROLL`
  Name=`echo $line | cut -d "," -f1`
  EmployeeID=`echo $line | cut -d "," -f2`
  EmployeeHP=`echo $line | cut -d "," -f3`
  EmployeeType=`echo $line | cut -d "," -f4` 

  #Check if entry exist in records
   if [ `count_lines "^${Name},"` -eq 0 ]
   then
       echo "Error: This particular record does not exist!!"
   else
      echo "$Name is ${EmployeeType} employee."


   if [ "$EmployeeType"="Salaried" ]
   then
    echo $EmployeeType  
    echo -en "Enter Weekly Salary :"
    read wsalary
    echo

   elif ["$EmployeeType"="Hourly" ]
   then
    echo -en "Enter hourly wage:"
    read hsalary
    echo -en "Enter hours worked this week:"
    read hours
    let "hwages = hsalary * hours"
    echo -en "Gross wages: \$$hwages"
    echo 

   elif ["$EmployeeType"="Commission" ]
   then
    echo -en "Enter Weekly Total Sales:"
    read csales
    echo -en "Gross wages:"
    read cwages
    echo 

   fi
   fi
   echo -en "Hit [Enter] to return to main menu..."
   read 

}

1 Answer 1

3

This is problem area:

if [ "$EmployeeType"="Salaried" ]

You need spaces here around = operator:

if [ "$EmployeeType" = "Salaried" ]

and here:

elif [ "$EmployeeType" = "Hourly" ]

and here:

elif [ "$EmployeeType" = "Commission" ]
Sign up to request clarification or add additional context in comments.

4 Comments

Hi anubhava, thanks but hit below error: ./Assignment2.sh: line 187: [Commission: command not found ./Assignment2.sh: line 197: [Commission: command not found
Apply all the suggestions into your script and then test it. If doesn't work then post your updated script in your question.
Hi.. sorry it works now. :) Thank you so much. Appreciate your help.
That's perfect, please consider accepting this question whenever SO permits you to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.