bash中的算术计算

bash中的算术计算,bash,shell,Bash,Shell,我是bash脚本的初学者。当我在测试自己时,我遇到了这个问题从用户处获取一个整数作为输入,乘以5,然后打印结果是否大于14。 我的剧本有点像这样 #!/bin/bash echo "Insert an Integer" read input echo $((input*5)) num1 =$((input*5)) num2 =14 if [ $num1 \> $b ]; then echo "a is greater than b"; else echo "b is gr

我是bash脚本的初学者。当我在测试自己时,我遇到了这个问题从用户处获取一个整数作为输入,乘以5,然后打印结果是否大于14。 我的剧本有点像这样

#!/bin/bash
echo "Insert an Integer"
read input
echo $((input*5))
num1 =$((input*5))
num2 =14
if [ $num1 \> $b ];
then 
    echo "a is greater than b";
else
    echo "b is greater than a";
fi;

我能得到一些帮助吗?

我发现这里有一些问题。
$b
突然从哪里来? 什么是a和b?为什么echo语句谈论
a
b

您还存在一些明显的语法错误,如果运行该脚本,您将看到这些错误

试试这个:

#!/bin/bash
echo "Enter an Integer"
read input
echo "You entered: $input"
num1=$((input*5))
echo "$input multiplied by 5 is $num1" 
num2=14
if [ $num1 -gt  $num2 ];
then 
        echo "$input multiplied by 5 is greater than 14"
    else
        echo "$input multiplied by 5 is NOT greater than 14"
fi
(())是用于所有算术运算(包括测试)的括号,因此您可以执行以下操作:

#!/bin/bash

read -p "Enter an integer: " input

echo "You entered: $input"

(( num1 = input * 5 ))

echo "$input multiplied by 5 is $num1"

num2=14

if (( num1 > num2 ))
then
  echo "$input multiplied by 5 is greater than 14"
else
  echo "$input multiplied by 5 is NOT greater than 14"
fi