Hi,
I'm developing a script which will have a lot of options to be checked for and will be setting things / doing further things accordingly.
I'm using a LOT of nested if, elif, else throughout my script. In some cases 5 to 6 levels deep. I'm facing some very basic problems. I've torn my hair, but am unable to understand what's wrong here.
SERVER_OS="WINDOWS"
SERVER_NAME="testServer"
SERVER_TYPE="APPSERVER"
BASIC_INSTALLER_PATH="/data2/builds/release/438"
if [ $SERVER_OS = "WINDOWS" ]
then
echo "in first if"
elif [ $SERVER_OS = "LINUX" ]
then
PROC_ARCH=`uname -p`
if [ $PROC_ARCH = "x86_64" ]
if [ $SERVER_TYPE = "APPSERVER" ]
then
BUILD_PATH=`ls "$BASIC_INSTALLER_PATH" | grep "appserver-rhas4.0"`
elif [ $SERVER_TYPE = "AGENT" ]
then
BUILD_PATH=`ls "$BASIC_INSTALLER_PATH" | grep "agent-rhas4.0-x86_64"`
else
echo "Unknown / Unsupported Server Type encountered under OS Linux 64-bit. Server Type: $SERVER_TYPE"
exit 1
fi
else
if [ $SERVER_TYPE = "APPSERVER" ]
then
BUILD_PATH=`ls "$BASIC_INSTALLER_PATH" | grep "appserver-rhas3.0"`
elif [ $SERVER_TYPE = "AGENT" ]
then
BUILD_PATH=`ls "$BASIC_INSTALLER_PATH" | grep "agent-rhas3.0"`
else
echo "Unknown / Unsupported Server Type encountered under OS Linux 32-bit. Server Type: $SERVER_TYPE"
exit 1
fi
fi
else
echo "in final else"
fi
If I run this through SH or BASH, it gives me an error on line 23
test.sh: line 23: syntax error near unexpected token `else'
test.sh: line 23: ` else'
If I run this through a shell based on ZSH (our product is based on this and this is what I would be finally running the script on), I get this:
test.sh:35: parse error near `else'
Funny part is, if I remove the last 3 lines, (below), the script runs in our ZSH based shell but still gives the same error via BASH. But not sure how it's doing that as the number of fi's don't match the number of if's.
else
echo "in final else"
fi
Some help / explanation here? Am I missing something very obvious? Or probably is my understanding of nested if else incorrect?