Reputation: 425
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
}
Upvotes: 1
Views: 101
Reputation: 784938
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" ]
Upvotes: 3