Once a process has opened a file (45.20), UNIX won't delete the file until the process closes it. (The rm command only removes a link to the file from a directory, not the file itself.)
I've heard arguments (24.3) about whether removing a file while it's open is a good idea. If you want to run a set of commands from a file, but not let anyone else read the list of commands you're using, you can write a shell script that removes itself before doing anything else. (You should be aware that if you use a filesystem mounted by NFS (1.33), NFS will just rename the "removed" file to a hidden filename (16.11) like .nfsXXXXX.)
Here's a simple self-removing shell script:
%cat doit
rm doit # by now, shell has opened this file; we can remove it ls doit make bigprog ... %sh doit
ls: doit not found cc -target sun4 -c routine.c ...
Here's a more typical script that opens and removes a file in /tmp (21.3):
exec <&- | % |
---|
-