Bash Syntax error: "[[: not found"

I am working with a bash script that is currently running on a server (RHEL4). I am developing on my laptop with Ubuntu 10.04, but I do not think the platform is causing the problem.

Here's what happens: I have a skeleton script that calls another script that does most of the work. However, it calls getConfig.sh calls a lot. getConfig.sh basically just parses some command line argument (using getopts) and calls a Java program to parse some XML files. In any case, getConfig.sh raises a lot of errors (but still seems to work).

Here is the message I receive

getconfig.sh: 89: [[: not found
getconfig.sh: 89: [[: not found
getconfig.sh: 94: [[: not found

I get these three errors every time it starts; however, the script exits and the Java code is executed.

Here's the conditional 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}"
 fi 

Line 89 is "parseOptions $ *" and line 94 is "fi"

Thanks for answers.

+4
source share
2 answers

If your script is executable and you execute it as ./getconfig.sh , the first line of your script should be:

 #!/bin/bash 

Without this shebang line, your script will be interpreted by sh , which does not understand [[ in if .

Otherwise, you should run the script as bash getconfig.sh , not sh getconfig.sh . Even if your default shell is bash, scripts run with sh will use the reduced bash feature set to be more compatible with the POSIX standard. [[ - is one of the functions that are disabled.

+26
source

If you are checking for equality, shouldn't if?

if [[ "${debugMode}" = "true" ]]; then .... fi

0
source

All Articles