TIP: Click on subject to list as thread! ANSI
echo: unix
to: Merlin
from: Angus McLeod
date: 2008-05-21 20:05:06
subject: Scipt in FreeBSD

Re: Scipt in FreeBSD
  By: Merlin to All on Fri Dec 22 2006 13:07:00

 > I need to write a csh script that looks for a file and if it exists and
 > its length is not 0 then it does something...
 > 
 > ie.
 > 
 > if exist /usr/filename.txt AND length > 0  then
 > 	do this
 > 	and this
 > 	and this
 > 
 > 
 > Can someone give me a quick how-to lesson!

I don't use csh, but you can probably do it with a single invocation of 
'find'.  Something like

	/usr/bin/find /dir/to/look -maxdepth 1 -name name.of.file \
		-size +1c -exec /usr/bin/ls -l {} \;

This example runs "/usr/bin/ls -l" on the file, if it exists in the 
directory and is 1 byte (or more) in size.

If you really want a csh script it will probably go something like:

	#! /bin/csh
	if ( -f /usr/filename.txt && ! -z /usr/filename.txt ) then
		. . .
	endif

but I'd really suggest you confer with the csh man-page and TEST that 
little fragment before you rely on it for anything, because as I said, I 
don't use csh.
---
Playing: "Private affair" by "Leah Andreone" from the
"Alchemy" album
 þ Synchronet þ Linus is a regular at The ANJO BBS.  No, Linus Brathwaite!
--- SBBSecho 2.12-Win32
* Origin: Joe's Computer & BBS -= joesbbs.synchro.net =- (1:275/412)
SEEN-BY: 10/1 3 14/250 34/999 90/1 120/228 123/500 140/1 222/2 226/0 236/150
SEEN-BY: 249/303 250/306 261/20 38 100 1404 1406 1418 266/1413 280/1027
SEEN-BY: 320/119 393/68 396/45 633/104 260 267 690/682 734 712/848 800/432
SEEN-BY: 801/161 189 2222/700 2320/100 105 200 2905/0
@PATH: 275/412 400 100 140/1 261/38 633/260 267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.