Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于验证linux上make版本的Shell脚本_Linux_Bash_Shell - Fatal编程技术网

用于验证linux上make版本的Shell脚本

用于验证linux上make版本的Shell脚本,linux,bash,shell,Linux,Bash,Shell,我试图编写这个shell脚本来验证linux上安装的make版本,但无法使其正常工作。如果有人能指出我在这里遗漏了什么,那就太好了 OUTPUT="$(make --version | head -1)" echo "${OUTPUT}" | grep -o '[0-9]*[\.][0-9]*' OP="$(echo \"${OUTPUT}\" | grep -o '[0-9]*[\.][0-9]*')" echo "${OP}" if [ $OP -ge 3.82 ]; then e

我试图编写这个shell脚本来验证linux上安装的make版本,但无法使其正常工作。如果有人能指出我在这里遗漏了什么,那就太好了

OUTPUT="$(make --version | head -1)"
echo "${OUTPUT}" | grep -o '[0-9]*[\.][0-9]*'

OP="$(echo \"${OUTPUT}\" | grep -o '[0-9]*[\.][0-9]*')" 
echo "${OP}"

if [ $OP -ge 3.82 ]; then
  echo "make version is greater than or equal to 3.82"
else:
  echo "make version is not greater than or equal to 3.82"
  exit 1
fi

您只能使用
test
(又称
[
)来比较字符串和整数,而不是类似的版本。下面两个问题向您展示了比较版本的方法:

不要在关键字else之后使用字符“:”

if [ $OP -ge 3.82 ]; then
  echo "make version is greater than or equal to 3.82"
else
  echo "make version is not greater than or equal to 3.82"
  exit 1
fi

突然,我看到if语句中的“op”应该是“$op”。另外,现在运行它时会发生什么?这是更改后的输出:3.82./test.sh:line 4:=3.82:找不到命令。/test.sh:line 7:[:-ge:unary operator expected您应该只在if语句中进行更改,而不是在设置变量的语句中进行更改。我的错误,现在的输出是:./test.sh:第7行:[:3.82:integer expression expectedBash本身不喜欢浮点数。请尝试
if[$(echo$OP'>='3.82|bc-l)-eq 1]