1

我想让用户键入选项 1-3,然后保存,然后与 .txt 文件中的其他输入一起。我试过使用 switch 但它似乎不起作用.. 只有 bash prog 的初学者..

    echo  "Select the Employee Type:"
echo "1- Salaried Employee"
echo "2- Hourly Employee"
echo "3- Commission Employee"
echo -en "Enter Selection: "
read choice

 case $choice in
         "1")  
    Type="Salaried Employee"
      break
      ;;
      "2") 
    Type = "Hourly Employee"
      break
      ;;
      "3") 
    Type ="Commission Employee"
      break
      ;;
          *) echo "Error: Please enter a choice between 1 - 7"
             echo -en "Hit [Enter] to return..."
             read
           ;;
  esac

   `if [ `count_lines "^${Name},"` -ne 0 ]                                                
   then
       echo "Error: Entry already exist!!"
   else 
       confirm "Are you sure you want to add the entry?[y/n]" 
       if [ $? -ne 0 ]
       then
           echo "Previous entry not updated!"           
       else 
           echo "Record is updated with new employee!!"
           echo "${Name},${Job},${Department},${Salary},${Type}" >> $PAYROLL
       fi       
   fi`
4

1 回答 1

0

这个脚本有几个问题:

  • 在另一种情况下,只有;;-- no break(跳出 do/for/while)
  • 在导致语法错误之前if和之后有一个额外的反引号;fi删除它们
  • 周围不得有空格,=例如Type = "Hourly Employee"Type ="Commission Employee"
于 2013-10-27T11:58:29.200 回答