Error while implementing nested if


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error while implementing nested if
# 1  
Old 03-30-2011
Error while implementing nested if

considering all variables like S01DEPOSITS will return numbers, i am trying to execute below statement
Code:
if [[ \( "$1"  >= "${S01DEPOSITS}" -a "$1" <= "${E01DEPOSITS}" \) -o \( "$1"  >= ${S04OVERDRAFT} -a "$1" <= ${E04OVERDRAFT}  \) -o \( "$1"  >= ${S05DEPOSITS} -a "$1" <= ${E05DEPOSITS} \) -o \( "$1"  >= ${S23DEPOSITS} -a "$1" <= ${E23DEPOSITS} \) -o \( "$1"  >= ${S25DEPOSITS} -a "$1" <= ${E25DEPOSITS} \) -o \( "$1"  >= ${S33DEPOSITS} -a "$1" <= ${E33DEPOSITS} \) -o \( "$1"  >= ${S26TLR_MAINT} -a "$1" <= ${E26TLR_MAINT} \) ]]
then
  echo "Queue DEP"
fi


while executing above if statement i am getting error as
Code:
if [[ \( "$1" qcheck.sh[100]: Syntax error at line 100 : `"$1"' is not expected.

pls help as soon as possible thanks

Last edited by Franklin52; 03-30-2011 at 05:24 AM.. Reason: Please use code tags
# 2  
Old 03-30-2011
Try one of these syntaxes:
Code:
[ condition1 -a condition2 ]    # ( condition1 AND condition2)
[ condition1 -o condition2 ]    # ( condition1 OR condition2)

or:
Code:
[[ condition1 && condition2 ]]    # ( condition1 AND condition2)
[[ condition1 || condition2 ]]    # ( condition1 OR condition2)

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 03-30-2011
Additionally if you are comparing numbers then use -ge or -gt operator and remove the quotes surrounding $1.
Code:
if [[ $1  -ge "${S01DEPOSITS}" && $1 -le "${E01DEPOSITS}" ... ]]
# ge -- greater than or equal to
# le -- less than or equal to

These 2 Users Gave Thanks to michaelrozar17 For This Post:
# 4  
Old 03-30-2011
Thanks michaelrozar17 and Franklin52 its working now...!!! SmilieSmilieSmilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error with nested if within an sqlplus task inside

Hi ALL, I am receving a "strange" error using a nested if within an sql operation inside: ./dom.ksh: syntax error at line 80 : `then' unmatched This is all my script code: in bold the step receiving the error. Any help would really aprrecieted ......! **** I have tried all the... (2 Replies)
Discussion started by: AndreaCecco
2 Replies

2. Shell Programming and Scripting

Mv: cannot access error after nested while loop

I have two methods...create_2_54 and create_2_55 I have added a nested while loop(previously it has just one loop) in create_2_54 the mv command(which comes first in 2_55) is not working. for name in `ls -1 1SMH_WICD_V5_2_5*.txt` ; do mv $name $nametmp.tmp unix2dos -ascii -437 $nametmp.tmp... (2 Replies)
Discussion started by: harish468
2 Replies

3. Shell Programming and Scripting

Intermittent "cp: cannot stat" error with nested loop

I have a bash script that has been running (on SUSE 9.3) dozens of times over the past couple of years without error. Recently it has been hitting intermittent “cp: cannot stat FILE: No such file or directory” errors. The script has nested loops that continuously process files in a... (2 Replies)
Discussion started by: jcart
2 Replies

4. Shell Programming and Scripting

nested if else -error

HI everyone, I am not able to find error in the script, when i run the script till line No. 20 i.e, read var4 everything runs fine. After that the script exits out. #!/bin/bash echo -e "Want dryrun OR merge: \n " read var1 if ] ; then echo -e "\n Please select from the given... (10 Replies)
Discussion started by: rishi.aradhya
10 Replies

5. Shell Programming and Scripting

Need help in implementing expect

Hello All, I am trying a shell script for automatically login to test servers and pulling the output of top command from all using expect. ----snippet of code --- #!/usr/bin/expect -f #!/bin/bash server1=10.251.222.51 server=("$server1") i=1 for exp_server in ${server}; do expect -c... (3 Replies)
Discussion started by: Renjesh
3 Replies

6. Shell Programming and Scripting

Help with implementing logging

I'm trying to add logging to an existing script which echos a number of lines to the screen. I've added a switch to the script that is going to suppress much of this output and put it in a file instead. The way I envisioned it was like this: $log would be set to either "" or the log files... (8 Replies)
Discussion started by: cheetobandito
8 Replies

7. Shell Programming and Scripting

Implementing Password

I am trying to implement a login screen to the following code how would i go about doing so. I have try to place the password in a variable using if statements which would usually work but as i have the system in a while loop i think i need to find another method. #!/bin/bash #Filename:... (4 Replies)
Discussion started by: warlock129
4 Replies

8. IP Networking

implementing ftp

i have a client server connection steady and running... but the problem here is that the file transfer is very crude and succeptible to risks... so i want to implement ftp.. can anybody suggest a way to implement it or any book to read? (4 Replies)
Discussion started by: damn_bkb
4 Replies

9. Programming

Implementing the redirection

Hi all I am facing a problem with redirection. Its somewhat related to parsing. I am following the following steps. 1. take the command and tokenize it. 2. if redirection is there then give it to redirection unit 3. if pipe is there give it to piping unit. 4. do until the command ends ... (0 Replies)
Discussion started by: mobile01
0 Replies

10. Programming

Implementing a shell

I'm implementing a shell in C that supports piping, output redirection, and background processing, and a few other commands. I was wondering how I'd go about implementing the output redirection. So, I'd open a file and I'd fork and execute the command. But how would I get stdout into the file? Any... (10 Replies)
Discussion started by: ununium
10 Replies
Login or Register to Ask a Question