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
Check existence of a login xavier054 UNIX for Advanced & Expert Users 10 03-06-2008 08:19 AM
How to check the file existence using shell scripting in Solaris-10 krevathi1912 SUN Solaris 2 11-26-2007 02:07 AM
Variable check for existence ? samit_9999 UNIX for Dummies Questions & Answers 2 12-05-2006 02:15 PM
check for FILES existence mpang_ Shell Programming and Scripting 3 06-28-2006 03:51 AM
File existence mpang_ Shell Programming and Scripting 2 03-27-2006 08:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 12-05-2007
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 556
Hi.

Looking at the man page:
Code:
#!/usr/bin/env csh

# @(#) s1       Demonstrate file existence test in csh.

echo
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version tcsh
echo

rm -f t1 t2
touch t1 t2

if ( -e t1 ) then
  echo " File t1 exists."
else
  echo " File t1 does not exist."
endif

rm t2
if ( -e t2 ) then
  echo " File t2 exists."
else
  echo " File t2 does not exist."
endif

exit 0
Producing:
Code:
% ./s1

(Versions displayed with local utility version)
tcsh 6.13.00

 File t1 exists.
 File t2 does not exist.
Adjust as necessary for your situation, see man page for details (this is done with csh as a link to tcsh) ... cheers, drl

_____
Obligatory scripting advice: "use Bourne family, not csh family, for scripting".
Reply With Quote
Forum Sponsor
  #9  
Old 12-05-2007
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,644
Quote:
Originally Posted by Raynon View Post
Code:
% ls *myfile
xxx1_myfile  xxx2_myfile
% ls *myfile|echo $status
0
% Reset tty pgrp from 7873 to 11434
I'm not really sure why you piped ls into echo $status, but as indicated previous status is the same as $? in bourne based shells.
Reply With Quote
  #10  
Old 12-05-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 321
Quote:
Originally Posted by reborg View Post
I'm not really sure why you piped ls into echo $status, but as indicated previous status is the same as $? in borne based shells.

Hi Reborg,

But what's your purpose of this statement " ls *_myfile >& /dev/null " before the statement " if ( $status == 0 ) then ". My code " ls *myfile|echo $status " was emulating this.

I tried to perform "echo $status" in a directory with files and in a directory without files, the output is always " 0 ". So what does $status really mean ?
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 07:32 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