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
I get those three errors every time it runs; however, the script completes and the Java code runs.getconfig.sh: 89: [[: not found
getconfig.sh: 89: [[: not found
getconfig.sh: 94: [[: not found
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With