syntax error in the if construct


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax error in the if construct
# 1  
Old 06-25-2009
syntax error in the if construct

Hi
can anyone tell me why is this code giving error

Code:
 
mode=$1
if [[ $# != 1]] || [[$mode != "find" && $mode != "kill" ]] then
    echo "MODES:"
    exit 1
fi

Thanks
# 2  
Old 06-25-2009
I moved "then" to the next line and it got compiled without any error.
Hope this will resolve your problem.

Cheers.
# 3  
Old 06-25-2009
You need to give space before ]] and after [[
Code:
if [[ $# != 1 ]] || [[ $mode != "find" && $mode != "kill" ]] then

But I will write like...
Code:
if [[ $# -ne 1 || ( $mode != "find" && $mode != "kill" ) ]]; then

# 4  
Old 06-25-2009
tried this too
Code:
 
mode=$1


if [[ $# -ne 1]] || [[ ${mode} -ne "find" && ${mode} -ne "kill" ]] then
    echo "MODES:"
fi

In both cases the error is common

Code:
 
Tes[2]: syntax error at line 5 : `${mode}' unexpected

# 5  
Old 06-25-2009
MySQL Hi, use like this

mode=$1
if [ $# -ne 1 ] || [ "${mode}" != "find" -a "${mode}" != "kill" ]; then
echo "MODES:"
fi


Thanks,
Phani Kumar
# 6  
Old 06-25-2009
Quote:
Originally Posted by rakeshawasthi
You need to give space before ]] and after [[
Code:
if [[ $# != 1 ]] || [[ $mode != "find" && $mode != "kill" ]] then

But I will write like...
Code:
if [[ $# -ne 1 || ( $mode != "find" && $mode != "kill" ) ]]; then


hi thanks
2nd way the code works..and give output as desired.
1st method compiles but doesnt give desired output.(couldnt figure out why?)

---------- Post updated at 03:58 PM ---------- Previous update was at 03:57 PM ----------

Quote:
Originally Posted by GaneshCPUX
I moved "then" to the next line and it got compiled without any error.
Hope this will resolve your problem.

Cheers.
hi moving then to the second line has helped.. thankyou
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Special IF construct syntax in UNIX

Hi, I don't understand && and || in this context. I thought && is for logical 'AND' and || is for logical 'OR'. && echo "Not empty" || echo "Empty" Please help Thank You (5 Replies)
Discussion started by: TomG
5 Replies

2. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

3. Solaris

"Estream construct failed" Error on Solaris i86pc

Hi Guys, From past some days, I am getting an error in /var/adm/messages which is as shown below. XXXXX02:/# cat /var/adm/messages |tail Sep 16 15:28:14 XXXX02 EV_AGENT: Agent Main --Estream construct failed. Err: EMULSocket::recv() Sep 16 15:31:49 XXXX02 EV_AGENT: Agent main --... (2 Replies)
Discussion started by: vivek.goel.piet
2 Replies

4. Linux

Ambiguous redirect error and syntax error when using on multiple files

Hi, I need help on following linux bash script. When I linux commands for loop or while loop on individual file it runs great. but now I want the script to run on N number of files so it gives me ambiguous redirect error on line 12 and syntax error on line 22 : (pls help ); #!/bin/bash #... (16 Replies)
Discussion started by: Madhusudan Das
16 Replies

5. Shell Programming and Scripting

Help with if-else construct

Hi all i have been trying to do a small 'question and answer' script using if-else statement and a combination of pipe. I have succeeded in allowing the user to login with user name and password stored in a sequence username/password in a file named "pass" like this: echo "please enter your... (14 Replies)
Discussion started by: arikutex
14 Replies

6. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

7. Programming

Newbie Question.. -> error: syntax error before ';' token

Hello, the following is generating a error at the line "tmprintf(&tmBundle, _TMC("{0}"),Prompt);"... a bit lost as I am diving into this debug... Thank you in advance... int H_YesNo(TMCHAR *Prompt, int DefVal) { TMCHAR YesNo = '\0'; tmprintf(&tmBundle, _TMC("{0}"),Prompt); while... (3 Replies)
Discussion started by: reelflytime
3 Replies

8. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

9. 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
Login or Register to Ask a Question