Register
It is currently Sat Nov 01, 2014 1:36 am

LOGICAL OR in a FOR statement


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Jan 25, 2012 8:37 am   

Joined: Wed May 19, 2010 9:56 am
Posts: 21
Does anyone know if you can use the LOGICAL OR in a for statement?

Something like:

for ANY_FILE in $MYDIR/*.bz2 -o ANY_FILE in $YOUR_DIR/*bz2
do
stuff
done

I've tried a couple of different iterations of the line to no avail so before I give up I thought I'd ask the pros.


Top
 Profile  
 PostPosted: Wed Jan 25, 2012 10:22 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 552
hi,

-o is part of test builtin only.
Code:
for ANY_FILE in {$MYDIR,$YOUR_DIR}/*bz2
do
stuff
done
see man bash /Brace Expansion


Top
 Profile  
 PostPosted: Fri Jan 27, 2012 1:19 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
What's the goal?
And how is this a OR, and not a AND?
There is no statement, so how for would know if it have to go in the former or latter path?

I think that you just want:
Code:
for any_file in "$mydir"/*bz2 "$yourdir"/*bz2; do
    ...
done


Notice that you can't expand variables inside brace expansions, so you can't use them in this case.


Top
 Profile  
 PostPosted: Fri Jan 27, 2012 7:41 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 552
Quote:
Notice that you can't expand variables inside brace expansions, so you can't use them in this case.
:-/
Code:
var1=foo; var2=bar
echo {$var1,$var2}
foo bar
seems to work though.

EDIT:
Code:
echo baz{$var1,$var2}baz
does not work. L-)

but
Code:
echo baz/{$var1,$var2}/baz
baz/foo/baz baz/bar/baz
o_O


Top
 Profile  
 PostPosted: Thu Feb 09, 2012 12:34 pm   

Joined: Wed May 19, 2010 9:56 am
Posts: 21
Thanks everyone for the input. Watael's solution is the one I stumbled across also from some other code I came across.


Top
 Profile  
 PostPosted: Mon Apr 02, 2012 5:00 pm   

Joined: Mon Feb 16, 2009 10:07 am
Posts: 19
Location: Paris - France
Quote:
And how is this a OR, and not a AND?

I would say a union is more like a OR and an intersection more like a AND - so in this case a OR :)


Top
 Profile ICQ YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP