[comp.unix.questions] rm delayed?

bglenden@mandrill.cv.nrao.edu (Brian Glendenning) (08/17/90)

Is it ever possible for a shell script snippet like the following:

touch /tmp/bad.$$
[...]
# Success
rm /tmp/bad.$$
[...]
if [ -f /tmp/bad.$$]
then
	echo failed
	exit 1
fi

To falsely report failure? This seems to be happening on our system
(convex). Is it true that if the rm succeeds it does so immediately,
or is it possible that some sort of race can be causing a false
apparent failure? I wouldn't have thought so, but I can't quite see
where else the script might be going wrong. Thanks!
--
       Brian Glendenning - National Radio Astronomy Observatory
bglenden@nrao.edu          bglenden@nrao.bitnet          (804) 296-0286

tchrist@convex.COM (Tom Christiansen) (08/17/90)

In article <BGLENDEN.90Aug17013335@mandrill.cv.nrao.edu> bglenden@mandrill.cv.nrao.edu (Brian Glendenning) writes:
>
>Is it ever possible for a shell script snippet like the following:
>
>touch /tmp/bad.$$
>[...]
># Success
>rm /tmp/bad.$$
>[...]
>if [ -f /tmp/bad.$$]
>then
>	echo failed
>	exit 1
>fi
>
>To falsely report failure? This seems to be happening on our system
>(convex). Is it true that if the rm succeeds it does so immediately,
>or is it possible that some sort of race can be causing a false
>apparent failure? I wouldn't have thought so, but I can't quite see
>where else the script might be going wrong. Thanks!

I've tested this on version 7, 8, 8.1 and 9 of the O/S, and here's what
I've found.  

1) First of all, you need a space between the $$ and the ] or you
   get a "test: ] missing" error.

2) Having fixed that, I never get the 'failed' to print, *BUT* on 
   version 7 and 8 of ConvexOS when put in a shell script like this:

    #!/bin/sh
    touch /tmp/bad.$$
    rm /tmp/bad.$$
    if [ -f /tmp/bad.$$ ]
    then
	echo failed
	exit 1
    fi

    The shell script itself returns an exit status of 1.  This
    is a problem that can really screw up your makefiles.  
    Fortunately, it's fixed by version 8.1, so if this is your
    problem, an upgrade will fix it.

--tom
--
  "UNIX was never designed to keep people from doing stupid things, because 
   that policy would also keep them from doing clever things." [Doug Gwyn]