Bash的语法错误:" [:找不到" [英] Bash syntax error: "[[: not found"
问题描述
我与当前工作的服务器(RHEL4)在bash脚本工作。我发展我的笔记本电脑与Ubuntu 10.04,但我不认为该平台是造成问题的原因。
下面是发生了什么:
我有一个调用另一个脚本,完成大部分工作的骨架脚本。然而,它使呼叫getConfig.sh了很多。 getConfig.sh基本上只是一些解析命令行参数(使用getopts的),并调用Java程序来解析一些XML文件。不管怎么说,getConfig.sh被扔了很多错误(但仍似乎工作)。
下面是我得到消息
getconfig.sh:89:[[:未找到
getconfig.sh:89:[[:未找到
getconfig.sh:94:[[:未找到块引用>我得到每次运行时这三个错误;然而,脚本完成和Java code运行。
这里的relavent code部分
parseOptions $ *如果[[$ {} debugMode==真]];然后
DEBUG = - DDEBUG =真
回声$ {JAVA_HOME} /斌/ java的$ {} DEBUG = -Djava.endorsed.dirs $ {} JAXP_HOME $罐子(目录名称$ 0)/GetXPath.jar $ {XML_FILE} $ {} xpath_查询
网络89号线parseOptions $ *和线94是网络连接
感谢您的答案。
解决方案如果你的脚本是可执行的,你正在执行它像
./ getconfig.sh
,第一行你的脚本需要是:#!/斌/庆典
如果没有家当行
,你的脚本将是
SH
PTED间$ P $不明白[
在如果
语句。否则,你应该运行脚本,比如
庆典getconfig.sh
,不可以SH getconfig.sh
。即使你的默认shell是bash,脚本与SH
将使用一组简化了bash的功能,以符合POSIX标准兼容的多运行。[
是被禁用的特色之一。I'm working with a bash script that is currently working on a server (RHEL4). I'm developing on my laptop with Ubuntu 10.04, but I don't think the platform is causing the problem.
Here's what's happening: I have a skeleton script that calls another script that does most of the work. However, it makes calls to getConfig.sh a lot. getConfig.sh basically just parses some command line argument (using getopts) and calls a Java program to parse some XML files. Anyways, getConfig.sh is throwing up lots of errors (but still seems to work).
Here's the message that I'm getting
getconfig.sh: 89: [[: not found
getconfig.sh: 89: [[: not found
getconfig.sh: 94: [[: not foundI get those three errors every time it runs; however, the script completes and the Java code runs.
Here's the relavent code section
parseOptions $* if [[ "${debugMode}" == "true" ]] ; then DEBUG="-DDEBUG=true" echo "${JAVA_HOME}/bin/java ${DEBUG} -Djava.endorsed.dirs=${JAXP_HOME} -jar $(dirname $0)/GetXPath.jar ${XML_File} ${XPath_Query}" fiLine 89 is "parseOptions $* and line 94 is "fi"
Thanks for the answers.
解决方案If your script is executable and you are executing it like
./getconfig.sh
, the first line of your script needs to be:#!/bin/bash
Without that shebang line, your script will be interpreted by
sh
which doesn't understand[[
inif
statements.Otherwise, you should run your script like
bash getconfig.sh
, notsh getconfig.sh
. Even if your default shell is bash, scripts run withsh
will use a reduced set of bash's features, in order to be more compliant with the POSIX standard.[[
is one of the features that is disabled.这篇关于Bash的语法错误:" [:找不到"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!