Sponsored Content
Top Forums Shell Programming and Scripting Problem with nested if...elif..else Post 302847171 by umar.shaikh on Monday 26th of August 2013 12:02:05 PM
Old 08-26-2013
Problem with nested if...elif..else

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. Smilie

Code:
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

Code:
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:

Code:
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.

Code:
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?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If..elif..else...fi

Hi all, I got some problems on executing the following scripts. Scripts: if ]; then echo "M${str}O 0 1" >> ${tempFile} elif ]; then echo "M${str}O 1 0" >> ${tempFile} else echo "M${str}O 0 0" >> ${tempFile} fi Error: "`;' is not expected." what's the problem? (2 Replies)
Discussion started by: Rock
2 Replies

2. Shell Programming and Scripting

problem with nested if stament

hi everybody: could anybody tell me what I'm doing wrong. I've tried to nest if staments like this: if condition1]; then if condition2];then if condition3];then commands else commands fi elif condition4];then commands... (3 Replies)
Discussion started by: tonet
3 Replies

3. Shell Programming and Scripting

Complex problem about nested for loops

Hey, I'm writing this bash script that will test print me many copies of the same program but with different combos of 4 variables being between 1 and 100. Here's the code: #! /bin/bash x=0 for ((a=1; a < 101; a++)) do for ((b=1; b < 101; b++)) do for ((c=1; c < 101; c++)) do for... (4 Replies)
Discussion started by: Silverlining
4 Replies

4. UNIX for Dummies Questions & Answers

have a problem with if elif loop .. plz help me with the script

count2=0 var2=NOT if then echo"Loop1" command="egrep ',$var1," if then echo "the command is OR" command=$command"|,$var3," echo "$command" elif then command=$command"| egrep ',$var3," else ... (4 Replies)
Discussion started by: Syms
4 Replies

5. Shell Programming and Scripting

nested loop problem

Please see the following script. basic="a b c" advance="d e f" A="basic advance" for g in $A do echo $g done The result would be obviously basic advance I want to ask how can i get the following result using $A in for loop a b c (5 Replies)
Discussion started by: mmunir
5 Replies

6. Shell Programming and Scripting

Perl nested array problem

I have a array reference which has some number of array references inside it.The nested array references also contains the array references. my $Filename = "sample.xml"; my $Parser = new XML::Parser( Style => 'tree' ); my $Tree = $Parser->parsefile( $Filename ); Here the $Tree is the... (6 Replies)
Discussion started by: karthigayan
6 Replies

7. Homework & Coursework Questions

if/elif help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is my problem for the class. Write a script that asks for the user's age. If it is equal to or higher... (6 Replies)
Discussion started by: aggie6970
6 Replies

8. UNIX for Advanced & Expert Users

if else elif

Hi all,i have configured the following script to check if the file exists or not, #!/bin/sh sleep 30 { FILEFULL=$1`date +$2`* if ; then echo $FILEFULL exist else echo "$FILEFULL File not Found" | mail -s 'server' myaccount@mydomain.com fi } but i have a problem, i need to... (2 Replies)
Discussion started by: charli1
2 Replies

9. Shell Programming and Scripting

If / elif

Hello all, I have a scenario where I take user input values and accordingly take actions say I run a script with sh scriptname -x GB -e txt (txt can also be text) I have used if clause for the first input (-x GB)and it is working fine Now for second the scenario is if then echo... (3 Replies)
Discussion started by: nnani
3 Replies

10. Shell Programming and Scripting

Problem with elif and else

Hello experts, I am having problems with ELIF. Please see the below code : read a; read b; read c; if || || ; then echo "EQUILATERAL" elif || || ; then echo "SCALENE" else echo "ISOSCELES" fi This code works fine for the EQUILATERAL case but fails completely for the... (5 Replies)
Discussion started by: H squared
5 Replies
Locale::Script(3)					User Contributed Perl Documentation					 Locale::Script(3)

NAME
Locale::Script - standard codes for script identification SYNOPSIS
use Locale::Script; $script = code2script('phnx'); # 'Phoenician' $code = script2code('Phoenician'); # 'Phnx' $code = script2code('Phoenician', LOCALE_CODE_NUMERIC); # 115 @codes = all_script_codes(); @scripts = all_script_names(); DESCRIPTION
The "Locale::Script" module provides access to standards codes used for identifying scripts, such as those defined in ISO 15924. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 15924 four-letter codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying scripts. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $script = code2script('phnx','alpha'); $script = code2script('phnx',LOCALE_SCRIPT_ALPHA); The codesets currently supported are: alpha, LOCALE_SCRIPT_ALPHA This is a set of four-letter (capitalized) codes from ISO 15924 such as 'Phnx' for Phoenician. It also includes additions to this set included in the IANA language registry. The Zxxx, Zyyy, and Zzzz codes are not used. This is the default code set. num, LOCALE_SCRIPT_NUMERIC This is a set of three-digit numeric codes from ISO 15924 such as 115 for Phoenician. ROUTINES
code2script ( CODE [,CODESET] ) script2code ( NAME [,CODESET] ) script_code2code ( CODE ,CODESET ,CODESET2 ) all_script_codes ( [CODESET] ) all_script_names ( [CODESET] ) Locale::Script::rename_script ( CODE ,NEW_NAME [,CODESET] ) Locale::Script::add_script ( CODE ,NAME [,CODESET] ) Locale::Script::delete_script ( CODE [,CODESET] ) Locale::Script::add_script_alias ( NAME ,NEW_NAME ) Locale::Script::delete_script_alias ( NAME ) Locale::Script::rename_script_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Script::add_script_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Script::delete_script_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.unicode.org/iso15924/ Home page for ISO 15924. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 1997-2001 Canon Research Centre Europe (CRE). Copyright (c) 2001-2010 Neil Bowers Copyright (c) 2010-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-06-03 Locale::Script(3)
All times are GMT -4. The time now is 06:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy