Barrie Stott wrote: > The script that follows is a cut down version of one that came from > elsewhere.
Thank you for your bug report but neither 'open' nor 'rm' have anything to do with bash. This is not a bug in the bash shell. This mailing list is for bug reports in the bash shell. > cp /tmp/x.html /tmp/$$.html > ls /tmp/$$.html > [ "$DISPLAY" ] && open /tmp/$$.html > ls /tmp/$$.html > rm -f /tmp/$$.html You have invoked open and then not waited for it to finish but instead removed the file it is going to work on. That is the problem. Open is launching in the background. Before it has a chance to run ls and rm are called in the script. Eventaully, some thousands of cpu cycles later, the action associated with open is called and by that time the file has been removed by the script. > My two questions are: > Why? > How can I change the script so that I can both view the file and > have it removed? See the man page for the Apple 'open' command. That is an Apple specific command not found on other systems. I do not have it available to me on my Debian GNU/Linux system for example. But I see an online man page for it here: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/open.1.html Using that man page I see that open has a -W option. -W Causes open to wait until the applications it opens (or that were already open) have exited. Use with the -n flag to allow open to function as an appropriate app for the $EDITOR environment variable. Therefore I infer that if you add the -W option to open that it will then wait for the application. Try this: #!/bin/sh cp /tmp/x.html /tmp/$$.html ls /tmp/$$.html [ "$DISPLAY" ] && open -W /tmp/$$.html ls /tmp/$$.html rm -f /tmp/$$.html I do not have a Mac and have no way to test the above but the documentation leads me to believe that it will work. Bob