我在运行shell脚本时遇到错误。请帮忙[脚本的意图是检查当前操作系统版本(RHEL / CentOS)是否小于7]
==================================错误============ ==================
./test.sh: line 5: 7]: No such file or directory
PHP 5.4 will be installed by default
=============================================== ========================
#!/bin/bash
# Script Name: test.sh
VERSION=`cat /etc/redhat-release|awk '{print $4}'|cut -d "." -f1`
if [ "$VERSION" < "7" ]
then
echo "PHP 5.4 need to be installed separately"
else
echo "PHP 5.4 will be installed by default"
fi`
答案 0 :(得分:1)
[
(test
)内置(和外部版本)(以及关键字[[
)不支持<
,>
样式算术比较。您需要算术比较运算符((
或使用-lt
(小于):
(( "$VERSION" < 7 ))
[ "$VERSION" -lt 7 ]
答案 1 :(得分:0)
#!/bin/bash
# Script Name: test.sh
VERSION=$(awk '{print $7}' /etc/redhat-release|cut -d "." -f1)
if [ "$VERSION" -lt 7 ];then
echo "PHP 5.4 need to be installed separately"
else
echo "PHP 5.4 will be installed by default"
fi
注意: