4 bash
我正在尝试安装一个程序,但在尝试配置它时不断收到此错误消息:
/configure: 919: [: unexpected operator
Run Code Online (Sandbox Code Playgroud)
我查看了代码,这就是配置文件的该部分中的内容:
if [ "$USENETCDFPAR" == "1" ] ; then
echo "Using parallel NetCDF via NETCDFPAR option"
fi
echo " "
Run Code Online (Sandbox Code Playgroud)
上网查了一下,我知道第一行有问题。但人们建议的任何改变都没有解决这个问题。有人有主意吗?
这里的“意外算子”确实是==
在 POSIX shell 中,字符串相等性的测试运算符是=:
$ sh -c '[ "a" = "a" ] && echo equal'
equal
Run Code Online (Sandbox Code Playgroud)
然而
$ sh -c '[ "a" == "a" ] && echo equal'
sh: 1: [: a: unexpected operator
Run Code Online (Sandbox Code Playgroud)
===是bash shell 中作为同义词提供的。来自CONDITIONAL EXPRESSIONS以下部分man bash:
string1 == string2
string1 = string2
True if the strings are equal. = should be used with the test
command for POSIX conformance.
Run Code Online (Sandbox Code Playgroud)
因此,该脚本的开发人员可能在一个系统上工作,该系统/bin/sh是一个符号链接,bash而在 Ubuntu 上,它是一个与 POSIX 兼容dashshell 的符号链接。
您可以在测试括号内替换==为,或将脚本的 shebang 行更改为=[ ... ]#!/bin/bash
| 归档时间: |
|
| 查看次数: |
2876 次 |
| 最近记录: |