What's wrong with this condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What's wrong with this condition
# 1  
Old 03-10-2012
What's wrong with this condition

Code:
if [ [ -n `grep ${TARGET_PATH_OK} ${PREPAVAL_TRAVAIL}/${EDI_DIRS_list}` ] && [ -d `grep ${TARGET_PATH_OK} ${PREPAVAL_TRAVAIL}/${EDI_DIRS_list}` ] ]
      then

Code:
 
+ [ -n
./prepaval.ksh[2578]: test: ] missing

Thanks in advance Smilie
# 2  
Old 03-10-2012
Hi try

Code:
if [[ -n `grep ${TARGET_PATH_OK} ${PREPAVAL_TRAVAIL}/${EDI_DIRS_list}` ]] && [[ -d `grep ${TARGET_PATH_OK} ${PREPAVAL_TRAVAIL}/${EDI_DIRS_list}` ]]

There should be no spaces between the square brackets.

Regards

Dave

Last edited by gull04; 03-10-2012 at 07:14 AM.. Reason: Incomplete
This User Gave Thanks to gull04 For This Post:
# 3  
Old 03-10-2012
Or remove the outer brackets..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 03-10-2012
But can you suggest me solution to avoid empty condition because of grep.
In conditio, I am finding a value in a list. If it is found then condition complete if it is not found then condition is incomplete, for which error thows.

Code:
test: argument expected

# 5  
Old 03-10-2012
Try putting double quotes around the back ticks...

-or alternatively make use of grep's return code, perhaps this will also server your purpose-
Code:
if grep -Fq "${TARGET_PATH_OK}" "${PREPAVAL_TRAVAIL}/${EDI_DIRS_list}" && [ -d "${TARGET_PATH_OK}" ]


Last edited by Scrutinizer; 03-10-2012 at 08:25 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 03-10-2012
Thanks for you suggestion, it worked Smilie

Now what is wrong with this:
Code:
        if [ "${FXML_line:1129:1}" = "S" -o "${FXML_line:1129:1}" = "H" ]

Error:
Code:
[2586]: "${FXML_line:1129:1}": bad substitution

# 7  
Old 03-10-2012
I am guessing your shell does not support this. You would need bash or ksh93.
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

2. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

3. Shell Programming and Scripting

What's wrong with this condition

if Please indicate the problem with this code Thanks in advance :) (4 Replies)
Discussion started by: ezee
4 Replies

4. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

5. Shell Programming and Scripting

syntax of if condition in ksh is wrong

The syntax of 'if' conditionals in bash and ksh seems different. I am trying to check for a particular version using 'if' in ksh. This very simple syntax gives syntax error. I have tried many variants, but no go. Please correct the syntax. Later I will expand it to 'if' and 'else'. #!/bin/ksh... (8 Replies)
Discussion started by: nivedhitha
8 Replies

6. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

7. Shell Programming and Scripting

Whats wrong with this IF condition?

I have four variables, dumpdata, defndata, compare1 and compare2 I want an IF statement condition which returns true when either dumpdata=defndata or (dumpdata<=compare1 and dumpdata>=compare2). But this is not working for me.. if (4 Replies)
Discussion started by: indianjassi
4 Replies

8. UNIX for Dummies Questions & Answers

What am I doing wrong?

I really just mess around in UNIX, for the most part, when I want to get something done. I can usually piece things together by searching for brief how-to's on Google, but the syntax errors in my following .sh file are really confusing me. I've got lots of programming experience in other places, so... (7 Replies)
Discussion started by: demonpants
7 Replies

9. Shell Programming and Scripting

Anything wrong with this

Does anyone see anything wrong with this. #getInfraFiles() #{ # cd Infra/$DAY # rm * # /usr/bin/ftp -i -n $LINE << cmd # user "$USER" "$PASSWD" # cd $INFRAPATH # binary # mget * # bye #} besides that its commented out (4 Replies)
Discussion started by: rcunn87
4 Replies

10. UNIX for Dummies Questions & Answers

Please tell me what do I do wrong here!

#!/usr/bin/csh # DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` mailx -s "$H-Myfile" email@email.com</home/mydir/myfile Thanks! (4 Replies)
Discussion started by: bobo
4 Replies
Login or Register to Ask a Question