Syntax error on script

Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Syntax error on script
# 1  
Syntax error on script

Evening All (or morning for some),
Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run.

Any help would be really apprecaited.

Code:
./testout: line 13: syntax error near unexpected token `else'

Code:
#!/bin/sh
if ($stat == 'a')
                {
                if (($Type=='p')|| ($Type=='b') || ($Type=='c') || ($Type=='d'))
                        {
                        if      ($Con == 'c' || $Con== 'p')
                                {
                                if      ($Con== 'p')
                                        {
                                        $Da = '1'
                                        echo "Migrated"
                                        }
                                else
                                        {
                                        $Da = '1'
                                        }
                                if ($Pl != "null")
                                        {
                                        $DT = '1'
                                        }
                                }
                        if ($Mig == ' not migrated 1')
                                {
                                echo "not migrated 1"
                                }
                        }
                else
                        {
                        $dar = '1';
                        echo "$DAR Decode 3"
                        }
                }
        else
                {
                $DAR = '1'
                echo "$DAR Decode 4"
                }

# 2  
Hi,

Seems perl syntax for if , variables are used.

IMHO, you need to update your code as follows:
Code:
#!/bin/sh
Type=p
Con=c
Pl=t

if (( $1 == 'a' )); then
	if (( $Type == 'p' )); then
        	if (( $Con == 'c' )) || (( $Con == 'p' )); then
                	if (( $Con == 'p' )); then
                        	Da='1'
                                echo "Migrated"
			else
				Da='1'
			fi
			if (( $Pl != "null" ));then
		                DT='1'
                	fi
		fi
	fi
fi


Code:
if ($stat == 'a')
                {
                if (($Type=='p')|| ($Type=='b') || ($Type=='c') || ($Type=='d'))
$Da = '1'

if condition requires space between two equal to symbol ie ==

Last edited by greet_sed; 12-23-2016 at 08:01 PM.. Reason: Update code & text
# 3  
Hello mutley2202,

A complete if-else needs to be closed by having fi at last but I see at least 3 pairs of if-else here which are not properly closed, kindly do close them properly.

Thanks,
R. Singh
# 4  
corrections but still has an issue

Updated to include the corrections however its still coming up with the same syntax fault.

Code:
./testout: line 13: syntax error near unexpected token `else'

Code:
#!/bin/sh
if ($stat == 'a')
                {
                if (($Type=='p')|| ($Type=='b') || ($Type=='c') || ($Type=='d'))
                        {
                        if      ($Con == 'c' || $Con== 'p')
                                {
                                if      ($Con== 'p')
                                        {
                                        $Da = '1'
                                        echo "Migrated"
                                        }
                                else
                                        {
                                        $Da = '1'
                                        }
                                fi
                                if ($Pl != "null")
                                        {
                                        $DT = '1'
                                        }
                                }
                        if ($Mig == ' not migrated 1')
                                {
                                echo "not migrated 1"
                                }
                        }
                else
                        {
                        $dar = '1';
                        echo "$DAR Decode 3"
                        }
                fi
                }
        else
                {
                $DAR = '1'
                echo "$DAR Decode 4"
                }
fi

# 5  
Quote:
Originally Posted by mutley2202
Updated to include the corrections however its still coming up with the same syntax fault.

Code:
./testout: line 13: syntax error near unexpected token `else'

Code:
#!/bin/sh
if ($stat == 'a')
                {
                if (($Type=='p')|| ($Type=='b') || ($Type=='c') || ($Type=='d'))
                        {
                        if      ($Con == 'c' || $Con== 'p')
                                {
                                if      ($Con== 'p')
                                        {
                                        $Da = '1'
                                        echo "Migrated"
                                        }
                                else
                                        {
                                        $Da = '1'
                                        }
                                fi
                                if ($Pl != "null")
                                        {
                                        $DT = '1'
                                        }
                                }
                        if ($Mig == ' not migrated 1')
                                {
                                echo "not migrated 1"
                                }
                        }
                else
                        {
                        $dar = '1';
                        echo "$DAR Decode 3"
                        }
                fi
                }
        else
                {
                $DAR = '1'
                echo "$DAR Decode 4"
                }
fi

I am afraid what you have posted is not shell syntax.
Here's an interpretation of what you have posted in shell syntax without any effort in correcting the logic flow of it:
Code:
if [ "$stat" = a ]
then
    if [ "$Type" = p ] || [ "$Type" = b ] || [ "$Type" = c ] || [ "$Type" = d ]
    then
        if [ "$Con" = c ] || [ "$Con" = p ]
        then
            if [ "$Con" = p ]
            then
                Da=1
                echo "Migrated"
            else
                Da=1
            fi

            if [ -n "$Pl" ]
            then
                DT=1
            fi
        fi

        if [ "$Mig"  = "not migrated 1" ]
        then
            echo "not migrated 1"
        else
            DAR=1
            echo "$DAR Decode 3"
        fi
    else
        DAR=1
        echo "$DAR Decode 4"
    fi
fi

Watch out for extra spaces between assignments.
Watch out for extra $ symbol when doing assignments.
if is not with curly bracket nor does it work like C or C++, the construct is
Code:
if [ ... ]
then
...
else
...
fi

There must be a space between expression [ expression ]
Double quote the variable "$name" when evaluating with single [ ].

Last edited by Aia; 12-23-2016 at 08:32 PM..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #254
Difficulty: Easy
'Steppenwolf' was the code name given to the first Apple Computer before it was announced publicly.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Syntax Error Script

Hi guys i'd like to show you this code of my script, where i couldn't find this error " #! /bin/bash #copiabin.sh: copia todos los archivos ejecutables a bin if then mkdir $HOME/bin fi # copia de archivos y contador N N=0 for ARCH in * do if # Si el archivo es... (9 Replies)
Discussion started by: Newer
9 Replies

2. Shell Programming and Scripting

Syntax Error in Script

Hi All, I am new to Unix, I have written the following script in ksh and get a syntax error :wall:. I need some help to figure out the error and reason. The script below uses some variables from an environment file, also it executes a sql file. The sql file is correct and has no problems. I... (1 Reply)
Discussion started by: disshort23
1 Replies

3. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

4. Shell Programming and Scripting

Syntax error in script

Hey guys keep having problems with the below script syntax error near unpexpected token '0' exit 0 I have two directorys backups and Usr in the usr i have sub dir's wp,ss,pic which i would like to back up (copy those directorys to the backups directory) with user acknowledgement from command line.... (2 Replies)
Discussion started by: Spartukus
2 Replies

5. Shell Programming and Scripting

Syntax error with a script

Hi I not sure what is wrong with my script... when I try to run it I get the follow error: "remove: syntax error at line 77: `end of file' unexpected" Thanks in advance for any help. ans=y while do while : do echo "Please enter a name that you... (3 Replies)
Discussion started by: simpsonjr
3 Replies

6. Shell Programming and Scripting

syntax error on script

Hello all, I am trying to write a little script to create a file and I keep getting the below error and cant see where my syntax mistake(s) is. please help... the script: FILE="/u/e477059/Unix_Machines/LISTS" for X in `cat ${FILE}/list` do ssh $X "echo $X; cd /var/tmp; ... (2 Replies)
Discussion started by: rookieuxixsa
2 Replies

7. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

8. Shell Programming and Scripting

Syntax error in script

I get this error when I try to run my script (BTW, this is a simple script I am supposed to write for my class) $ menuscript menuscript: syntax error at line 89 : `"' unmatched $ Here is the code (Any help is greatly appreciated) (Line numbers included) 1 #!/bin/ksh 2 ... (2 Replies)
Discussion started by: KindHead
2 Replies

9. Shell Programming and Scripting

syntax error in script !!

./disk_space_util.sh ./disk_space_util.sh: Syntax error at line 24 : `then' is not expected. ================================= cat disk_space_util.sh #!/bin/sh # # Parameter Settings ORA_LOG, ORA_SCRIPT, DBA_EMAIL_LIST -- (Set in .profile) bdf | sed "s/%/ /g" | sed "/Filesystem/d" |... (13 Replies)
Discussion started by: uuser
13 Replies

10. Shell Programming and Scripting

Syntax error in a script...

Hi All, I have been fighting with a syntax error for the last 2 days, still haven't got the solution. Could you please help me, your help will be greatly appreciated. In my script I am getting a error in a for loop, its similar to the one as is below. for v_id in v1 v2 v3 v4 do... (8 Replies)
Discussion started by: rajus19
8 Replies

Featured Tech Videos