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
What's wrong with this line: if ${TEST:?} ; then echo empty; fi meili100 UNIX for Dummies Questions & Answers 2 02-23-2008 07:45 AM
existing file to a fixed length file cmanand Shell Programming and Scripting 3 01-25-2008 01:50 PM
Creating a csv file based on Existing file skywayterrace Shell Programming and Scripting 3 12-02-2007 05:19 AM
how to add files to an existing tar file - HP-UNIX Nomaad UNIX for Dummies Questions & Answers 4 06-16-2006 03:44 PM
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 Display Modes
  #1 (permalink)  
Old 10-20-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
Stumble this Post!
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 (permalink)  
Old 10-20-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,659
Stumble this Post!
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 (permalink)  
Old 10-20-2005
Registered User
 

Join Date: Jul 2005
Posts: 45
Stumble this Post!
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 (permalink)  
Old 10-20-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,659
Stumble this Post!
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
Display Modes




All times are GMT -7. The time now is 01:25 PM.


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