命令未找到错误

Ali*_*ien 1 bash ubuntu

我收到一个错误,command not found不知道有什么问题.我认为我的代码存在问题.我需要用户输入付款.第一个用户输入ID,然后程序将找到具有该ID的人.然后程序会找到他[雇员,或每小时]的雇员类型然后从那里进入 if [$type="Salaried"]或' Hourly'编码并提示用户键入相应的数据

请告诉我该怎么做呢?

payroll()
{
  line=`grep -i "^${update_empID}," $data`
  empID=`echo $line | cut -d "," -f1`
  name=`echo $line | cut -d "," -f2`
  job=`echo $line | cut -d "," -f3`
  phone=`echo $line | cut -d "," -f4` 
  type=`echo $line | cut -d "," -f5`

   clear
   echo -e "Enter the pay"
   echo -en "Enter ID: "
   read empid_search

   #Check if particular entry to search for existed to perform deletion
   if [ `count_lines "^${empid_search},"` -eq 0 ]
   then
       echo "Error: This particular record does not exist!!"
   else
       echo "Please verify update of this employee's record: " #Prompt for confirmation of employee details
    echo
       echo "Employee's Details: "
       locate_lines "^${empid_search},"   #Find location of the entry     


   if [$type="Salaried"]
   then
    echo "$name is a Salaried"
    echo "Enter Salary :"
    read salary

     echo "${empID},${name},${job},${phone},${Type},${salary}" >> tmpfile ; mv tmpfile $data
       echo " particulars has been updated!!"
       fi      
    else
    echo "f"     
   fi

}
Run Code Online (Sandbox Code Playgroud)

文本文件

3,Frak,IT,9765753,Salaried
1,May,CEO,9789292,Salaried
5,Samy,Sales user,92221312,Commission
2,Orange,cleaner,935233233,Hourly
Run Code Online (Sandbox Code Playgroud)

错误:

  line 371: [=Salaried]: command not found
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 5

这是问题所在:

if [$type="Salaried"]
Run Code Online (Sandbox Code Playgroud)

在比较[和中的值时需要有空格]:

if [ "$type" = "Salaried" ]
Run Code Online (Sandbox Code Playgroud)

  • 是的,BASH语法有点僵硬,但也有一个原因,因为`/ bin/[`是一个外部程序,并且需要为任何程序空间提供参数. (2认同)