The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
if statement ramky79 Shell Programming and Scripting 6 05-29-2008 12:17 AM
IF Statement koti_rama Shell Programming and Scripting 3 04-29-2008 01:48 AM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 10:14 AM
using && in if statement .. jisha Shell Programming and Scripting 7 02-01-2008 03:52 AM
IF statement on a df -g hassanj UNIX for Advanced & Expert Users 1 12-18-2007 03:41 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-22-2004
Registered User
 

Join Date: Nov 2003
Location: Grimsby
Posts: 17
If statement

Hi i am trying to set up an IF statement that says if FILE1 exists or FILE2 exists do a command. I am struggling to remember what i need to put in for the OR statement. i have the following

if [ -a $FILE1 (or?) -a $FILE2 ]
then
run my command
fi

Would a | command work?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-22-2004
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Code:
if [ -a $FILE1 -o -a $FILE2 ]
 then
   run my command
fi
Reply With Quote
  #3 (permalink)  
Old 12-15-2004
Registered User
 

Join Date: Aug 2004
Posts: 141
Google

What if, I want to achieve and condition in between?
Reply With Quote
  #4 (permalink)  
Old 12-15-2004
Registered User
 

Join Date: Aug 2004
Posts: 141
Talking

I got the solution, you need to put -a.
Reply With Quote
  #5 (permalink)  
Old 12-16-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Just for info, newer shells like bash and ksh allow more "usual" short circuit operator syntax of && and || so you can do things like

[[ -d file1 && -d file2 ]] || echo "Both files are not directories"

i.e. with && for AND, || for OR

Cheers
ZB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0