1

我不确定为什么我的 if 语句不起作用。即使 $EmployeeType 是 Commission 或 Hourly,它也会提示输入 Weekly Salary。我应该使用 if 语句代替 elif 吗?我尝试使用所有 if 语句,但一直出现错误“意外标记“}”附近的语法错误”。请多多指教。

输出:

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 

}
4

1 回答 1

3

这是问题区域:

if [ "$EmployeeType"="Salaried" ]

您需要在运算符周围有空格=

if [ "$EmployeeType" = "Salaried" ]

和这里:

elif [ "$EmployeeType" = "Hourly" ]

和这里:

elif [ "$EmployeeType" = "Commission" ]
于 2013-11-07T15:12:06.687 回答