2013-11-04 178 views
1

我收到錯誤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 

} 

文本文件

3,Frak,IT,9765753,Salaried 
1,May,CEO,9789292,Salaried 
5,Samy,Sales user,92221312,Commission 
2,Orange,cleaner,935233233,Hourly 

錯誤:

line 371: [=Salaried]: command not found 

回答

5

這就是問題之行:

if [$type="Salaried"] 

你需要有空間,而在[和比較值:

if [ "$type" = "Salaried" ] 
+0

啊,的bash腳本的美麗:) –

+2

是BASH語法是有點刻板,但還有一個原因是因爲太'/斌/ ['是一個外部程序,並提供論據任何編程的,是米空間是必需的。 – anubhava

+0

@Alien:這是否適合你? – anubhava

相關問題