The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to add files to an existing tar file - HP-UNIX Nomaad UNIX for Dummies Questions & Answers 5 3 Weeks Ago 02:27 AM
What's wrong with this line: if ${TEST:?} ; then echo empty; fi meili100 UNIX for Dummies Questions & Answers 2 02-23-2008 08:45 AM
existing file to a fixed length file cmanand Shell Programming and Scripting 3 01-25-2008 02:50 PM
Creating a csv file based on Existing file skywayterrace Shell Programming and Scripting 3 12-02-2007 06:19 AM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 01:38 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-20-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
if test for empty and non-existing file

How to write this condition in ksh?

if myfile is empty or myfile does not exist
then
do action1
fi

is this OK?

if [[ -s "$myfile" ]] -o [[ -f "$myfile" ]] then
then
do action1
fi

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 10-20-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Quote:
Originally Posted by GNMIKE
How to write this condition in ksh?

if myfile is empty or myfile does not exist
then
do action1
fi

is this OK?

if [[ -s "$myfile" ]] -o [[ -f "$myfile" ]] then
then
do action1
fi

Thanks.

Code:
if [[ -s "$myfile" -o -f "$myfile" ]] ; then
#do action1
fi
Look at man test.

vino
Reply With Quote
  #3  
Old 10-20-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
Actually this did not work on HP-UX
However replacing the -o with || works

[[ cond1 || cond2 ]]

why is ksh so strange???

Last edited by GNMIKE; 10-20-2005 at 12:29 PM.
Reply With Quote
  #4  
Old 10-20-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
From man ksh

Code:
       [[ expression ]]
              Similar to the test and [ ... ] commands (described later), with
              the following exceptions:
                o    Field splitting and file name  generation  are  not  per-
                     formed on arguments.
                o    The  -a  (and) and -o (or) operators are replaced with &&
                     and ||, respectively.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:31 AM.


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

Content Relevant URLs by vBSEO 3.2.0