bash语法错误:未接受令牌Elif

我运行一个简单的脚本后得到这个消息:

第9行:在意外标记附近的语法错误elif第9行:elif [$ sales -le 20000];

我的代码:

#!/bin/bash echo "Please enter the how much sales you have done" read sales if [ $sales -le 5000 ]; then echo "your profit is $[$sales*0.25]" elif [ $sales -le 10000 ]; echo "your profit is $[$sales*0.1]" elif [ $sales -le 20000 ]; echo "your profit is $[$sales*0.15]" elif [ $sales -le 40000 ]; echo "your profit is $[$sales*0.2]" else echo "your profit is $[$sales*0.25]" fi 

  1. 你在elif之后错过了
  2. 你不能在bash中做浮点数学。

你可以使用这个脚本:

 #!/bin/bash read -p "Please enter the how much sales you have done: " sales if [ $sales -le 5000 ]; then pp='0.25' elif [ $sales -le 10000 ]; then pp='0.1' elif [ $sales -le 20000 ]; then pp='0.15' elif [ $sales -le 40000 ]; then pp='0.2' else pp='0.25' fi echo "your profit is " $(bc -l <<< "$sales * $pp")