Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!mcnc!garfield!muquit From: muquit@garfield.ncat.edu (MUHAMMAD A. MUQUIT) Newsgroups: comp.unix.questions Subject: Re: The "if ( -e filename )" blues... Message-ID: <1991Jun18.173828.22639@garfield.ncat.edu> Date: 18 Jun 91 17:38:28 GMT Sender: muquit@garfield.ncat.edu (MUHAMMAD A. MUQUIT) Organization: North Carolina A&T State University Lines: 74 In article <1991Jun17.195519.12713@murdoch.acc.Virginia.EDU> Edward Schwab writes: >Help! I'm trying to run a simple csh shell file that sets $OUT.out to an >output filename and $PROG to a program name, will search for $OUT.out, and >delete it... I'm trying to do an "if ( -e $OUT.out ) set x=$<", which will >wait for an ENTER before continuing with the program... The only thing is >that the "if ( -e )" statement (that searches for the existance of the file) >runs if there is an actual $OUT.out file or not... **sigh** How can I make >this wait for an enter keypress ONLY if $OUT.out exists??? All of the other >if -e's work (the echos and the rm...) BTW, the actual executable is called >.$PROG; this is called up by $PROG... :) > >I hope this message makes SOME sense when you look at the actual shell script >below: >----------------------------------------------------------------------------- >#!/bin/csh >setenv OUT for005 >setenv PROG asymtc1 >if ( -e $OUT.out ) clear >if ( -e $OUT.out ) echo '******************************************************' >if ( -e $OUT.out ) echo 'You have a leftover '$OUT'.out file. Since '$PROG'' >if ( -e $OUT.out ) echo 'will end up choking on this leftover file, I am going' >if ( -e $OUT.out ) echo 'to delete it for you. If you do not want me to' >if ( -e $OUT.out ) echo 'delete it, hit ^C, ENTER, and rename it to a different' >if ( -e $OUT.out ) echo ' filename.' >if ( -e $OUT.out ) echo '******************************************************' >if ( -e $OUT.out ) echo ' ' >if ( -e $OUT.out ) echo ' If you want it deleted, press ENTER now to continue.' >if ( -e $OUT.out ) set x=$< >if ( -e $OUT.out ) rm $OUT.out >.$PROG >echo 'Now filtering...' >mv $OUT.out $OUT.asa >asa $OUT.asa >$OUT.out >rm $OUT.asa >echo ' ' >echo 'Done! File written to '$OUT.out'.' >echo ' ' >------------------------------------------------------------------------------- > > Thanks, > - Ed (eas@turing.acs.virginia.edu) > (eschwab@polaris.cv.nrao.edu) What about this? ----------------------------------------- #!/bin/csh setenv OUT for005 setenv PROG asymtc1 if ( -e $OUT.out ) then echo -n "continue [y]?" set x=$< if ( $x != n ) then echo "Things you want to do here" endif else echo "file does not exist, exiting shell" endif ------------------------------------------ is this what you want? Thanks. - - :+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+: : Muhammad A. Muquit Office: 126 Graham Hall : : Graduate Student Phone: (919) 334-7737 ext 53 : : Dept. of Civil Engineering e-mail: muquit@garfield.ncat.edu : : North Carolina A&T State University or, muquit@vanity.ncat.edu : : Greensboro, NC 27411 : :+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+:+: --