Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash syntax error: "[[: not found" [duplicate]

Tags:

bash

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 found

I 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}" fi

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

Thanks for the answers.

like image 249
Justin Avatar asked Aug 03 '10 22:08

Justin


People also ask

What does bash command not found mean?

Sometimes when you try to use a command and Bash displays the "Command not found" error, it might be because the program is not installed on your system. Correct this by installing a software package containing the command.

How fix Unexpected end of file in Linux?

An Unexpected end of file error in a Bash script usually occurs when you there is a mismatched structure somewhere in the script. If you forget to close your quotes, or you forget to terminate an if statement, while loop, etc, then you will run into the error when you try to execute your Bash script.

What is difference between bin sh and bin bash?

Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different. Bash (bash) is one of many available (yet the most commonly used) Unix shells. Bash stands for "Bourne Again SHell",and is a replacement/improvement of the original Bourne shell (sh).


1 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 [[ in if statements.

Otherwise, you should run your script like bash getconfig.sh, not sh getconfig.sh. Even if your default shell is bash, scripts run with sh 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.

like image 130
Dennis Williamson Avatar answered Sep 23 '22 21:09

Dennis Williamson