运行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`

最佳答案

[test)内置(和外部)(以及关键字[[)不支持<>类型的算术比较。您需要算术比较运算符((或使用-lt(小于):

(( "$VERSION" < 7 ))
[ "$VERSION" -lt 7 ]

关于linux - Shell脚本中的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38844928/

10-15 03:31