|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
if [ -a $FILE1 -o -a $FILE2 ] then run my command fi |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Google
What if, I want to achieve and condition in between? |
|
#4
|
|||
|
|||
|
I got the solution, you need to put -a.
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 04:31 PM |
| IF statement | Great Uncle Kip | UNIX for Dummies Questions & Answers | 4 | 04-09-2009 07:17 AM |
| How is use sselect statement o/p in insert statement. | nkosaraju | Shell Programming and Scripting | 2 | 08-06-2008 09:26 PM |
| If statement - How to write a null statement | april | Shell Programming and Scripting | 3 | 04-16-2008 01:14 PM |
| if statement in ksh | gfhgfnhhn | UNIX for Dummies Questions & Answers | 3 | 10-20-2006 09:37 AM |
|
|