If statement | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

If statement

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-22-2004
mariner mariner is offline
Registered User
 
Join Date: Nov 2003
Last Activity: 3 September 2010, 9:42 AM EDT
Location: Grimsby
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Sponsored Links
    #2  
Old 10-22-2004
google's Avatar
google google is offline Forum Advisor  
Advisor
 
Join Date: Jul 2002
Last Activity: 17 June 2009, 5:17 PM EDT
Location: Atlanta
Posts: 740
Thanks: 0
Thanked 2 Times in 2 Posts

Code:
if [ -a $FILE1 -o -a $FILE2 ]
 then
   run my command
fi

Sponsored Links
    #3  
Old 12-15-2004
videsh77 videsh77 is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 22 April 2014, 2:17 PM EDT
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
Google

What if, I want to achieve and condition in between?
    #4  
Old 12-15-2004
videsh77 videsh77 is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 22 April 2014, 2:17 PM EDT
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
Computer

I got the solution, you need to put -a.
Sponsored Links
    #5  
Old 12-16-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
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
The Following User Says Thank You to zazzybob For This Useful Post:
Lucky4U (06-26-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with for statement within while statement bbbngowc Shell Programming and Scripting 1 05-07-2011 05:31 PM
IF statement Great Uncle Kip UNIX for Dummies Questions & Answers 4 04-09-2009 08:17 AM
How is use sselect statement o/p in insert statement. nkosaraju Shell Programming and Scripting 2 08-06-2008 10:26 PM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 02:14 PM
if statement in ksh gfhgfnhhn UNIX for Dummies Questions & Answers 3 10-20-2006 10:37 AM



All times are GMT -4. The time now is 05:57 PM.