Multiple Find Conditions in IF Statement - UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Multiple Find Conditions in IF Statement - UNIX
# 1  
Old 05-10-2012
Multiple Find Conditions in IF Statement - UNIX

When I try the below if Condition with single condition its working fine.
But when I try to Club both its working . But giving wrong results.

In my case
cond1 = -f ${filename1} = true
cond2 = -f ${filename2} = true

But Cond1 & Cond2 is resulting in False ??? Please advise

Code:
filename1='/home/abc????????'
filename2='/home/yyy????????'
[COLOR=#000080] 
if [[ -f ${filename1} && -f ${filename2} ]]
then
echo 'files Available' >>${log}
else 
echo 'Files Not Available' >>${log}
fi

Thank you Smilie
# 2  
Old 05-10-2012
I don't see anything wrong with that, but then, you haven't said what your shell is. Those ????'s will expand, by the way, unless you put the filenames in "quotes". Try -a instead of && too.
# 3  
Old 05-10-2012
Its Korn Shell. I really dont understand why this is not giving correct results ... Smilie

Last edited by radoulov; 05-10-2012 at 04:27 PM.. Reason: Spelling: Corn -> Korn
# 4  
Old 05-10-2012
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 5  
Old 05-10-2012
Quote:
Originally Posted by Shiny_Reddy
Its Corn Shell. I really dont understand why this is not giving correct results ... Smilie
Did you try adding quotes like I suggested, so the ????? don't accidentally expand into one or more different filenames?
# 6  
Old 05-10-2012
Thank you Corona688 for your help.


FYI - Same code worked. I tried creating a new file. I got it ... Probably their where some bad characters (Edior issues)
This User Gave Thanks to Shiny_Reddy 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

Linux find command : how to use multiple conditions

Hello. I need to find all files but excluding some because I need to exclude some sub-folders I need to exclude some filenames Files must be within two dates. The result is sent to a function I cannot achieved to put together the date conditions, the folder conditions and the... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

How to Check Multiple conditions in IF statement?

I wish to check two conditions inside the if statement Condition 1: The two file contents should be identical // using cmp command for this. Condition 2: The two filenames should NOT be the same. This is what i did in vain. if ]; then where entry1 and entry2 are ls *.txt | while... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Shell Programming and Scripting

Multiple conditions inside if statement

I was trying to write multiple conditions inside the if statement but its not working. export VAR_NM=abc.txt export CURR_DT=20131011 export PREV_DT=20131012 if && then echo "Yes" else echo "NO" fi It should return Yes but returning NO always.Appreciate any help. (3 Replies)
Discussion started by: dr46014
3 Replies

4. Shell Programming and Scripting

Checking multiple conditions in UNIX IF-ELSE

I am posting this info only after having confirmed the fact that there are no prior posts avialable that serves my purpose . In my Korn Shell script file , there are two shell variables which needs to be tested within a single if statement . Sample variables : $var1 and $var2 The check... (8 Replies)
Discussion started by: kumarjt
8 Replies

5. Shell Programming and Scripting

Multiple conditions inside my if statement

Hello, I am using shell scripting and I am recieving odd results from my if statement if I want it to enter the loop only if L1 is equal to zero and one of the other criteria are filled, however it is entering at other times as well. What can i do to fix this? i tried seperating it... (6 Replies)
Discussion started by: ryddner
6 Replies

6. Shell Programming and Scripting

Multiple Conditions Perl if Statement

Hello, I'm trying to put together a script that involves pulling data from a config file. I'm attempting to write an if statement to validate one of the pieces of data from the config file, but I think I'm fat fingering it somehow. $config{VALUE} is being pulled from a config file but can only... (4 Replies)
Discussion started by: Picch
4 Replies

7. Shell Programming and Scripting

trying to find match from multiple string if statement

I'm trying to create what (should be) a simple bash script that will pull computer name and use that info to bind to one of three servers. Is there any way to do this without having a text file with the names of the servers and associated computer names? (5 Replies)
Discussion started by: jacobsbigbro1
5 Replies

8. Shell Programming and Scripting

Multiple conditions in a CASE statement

is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be CASE $vendor OR $alias condition 1) statements; condition 2) statements; etc. esac but I keep... (25 Replies)
Discussion started by: Straitsfan
25 Replies

9. Shell Programming and Scripting

If statement with multiple conditions

I have a script that runs on multiple servers. What I want to do is have the script do the following: if $(hostname) is equal to server or server2 then TO_DIR=go else TO_DIR=stop fi I have tried: if if ] Server is hpux. any ideas? (1 Reply)
Discussion started by: cpolikowsky
1 Replies

10. UNIX for Dummies Questions & Answers

Multiple conditions in find or ls stmts

I'm looking for syntax to include two search patterns in a find or ls command. e.g. find BTIME_ACTUAL_HRS* OR BTIME_SCHEDULED_HRS* tia (5 Replies)
Discussion started by: mavsman
5 Replies
Login or Register to Ask a Question