1

I've received an error command not found not sure what is wrong. i think there is a problem with my code. i need user to enter the pay. first user enter the ID, then the program will find the person with that ID. then program will find the type of employee he is [salaried, or hourly] then from there it will goes to if [$type="Salaried"] or' Hourly' code and prompt user to key in the respective data

please advise how do i go about doing it?

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

}

TEXT FILE

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

error:

  line 371: [=Salaried]: command not found

1 Answer 1

5

This is the problem line:

if [$type="Salaried"]

You need to have spaces while comparing values in [ and ]:

if [ "$type" = "Salaried" ]
Sign up to request clarification or add additional context in comments.

2 Comments

Ah, the beauty of bash-scripts :)
Yes BASH syntax is little rigid but there is a reason too since /bin/[ is an external program and to provide arguments to any progra m spaces are required.

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.