本文介绍了bash语法错误:不可接受的令牌省略号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了一个简单的脚本后收到了以下消息:

I got this message after I ran a simple script:

我的代码:

    #!/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. 之后丢失了then
  3. 您无法在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")

这篇关于bash语法错误:不可接受的令牌省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 01:40