The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting Command line on HP-UX rucha_mahajan HP-UX 2 05-12-2008 01:06 AM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
Add line command felixwhoals UNIX for Dummies Questions & Answers 3 12-16-2007 08:12 PM
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 3 09-04-2007 12:13 AM
how to tell which OS via command line hankooknara UNIX for Dummies Questions & Answers 4 05-15-2007 08:39 PM

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

Join Date: Jun 2005
Posts: 15
Use of IF command in the command line.

What is the command line syntax for the if exist command in Unix like in DOS/WIN which test for the existance of a file?

Is the syntax the same in a script?

Thanx
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-22-2005
Registered User
 

Join Date: Oct 2003
Location: United Kingdom
Posts: 37
A couple of options

.ksh

if [[-f filename]] for existence

If I can remember correctly...

if [[-s filename]]for non-empty
Reply With Quote
  #3 (permalink)  
Old 06-22-2005
Registered User
 

Join Date: Jun 2005
Posts: 15
Does this syntax work on the command line?

I am getting a ">" back from my command.
Reply With Quote
  #4 (permalink)  
Old 06-22-2005
Registered User
 

Join Date: Oct 2003
Location: United Kingdom
Posts: 37
yeah..., that is the continuation marker.

You can type:

if [[ -f filename]] then [ENTER]
echo "File exists" [ENTER]
else [ENTER]
echo "File does NOT exist" [ENTER]
endif [ENTER]

...and it should respond accordingly
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:08 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