我认为BASH中的括号是用于布尔测试的

时间:2015-10-05 05:05:18

标签: linux bash ssh

我尝试运行这个BASH脚本,它在第4行说它缺少一个括号。

#!/bin/bash

#Given an integer value, write a script to check to see if it is between     10 and 20(inclusive)
if [$value -le 20] && [$value -ge 10]; then
        echo "$value in in range"
else
        echo " $value is out of range"
fi

我在Linux服务器上通过SSH进行此操作。

1 个答案:

答案 0 :(得分:1)

试试这个

您需要在括号前后放置空格。

#!/bin/bash

#Given an integer value, write a script to check to see if it is between     10 and 20(inclusive)
if [ $value -le 20 ] && [ $value -ge 10 ]; then
        echo "$value in in range"
else
        echo " $value is out of range"
fi

以下是我们需要这样做的原因 Why should there be a space after '[' and before ']' in Bash?