Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!husc6!cmcl2!brl-adm!adm!franco@MIKEY.BBN.COM From: franco@MIKEY.BBN.COM (Frank A. Lonigro) Newsgroups: comp.unix.wizards Subject: /bin/test and stat(2) Message-ID: <9977@brl-adm.ARPA> Date: Mon, 26-Oct-87 21:05:10 EST Article-I.D.: brl-adm.9977 Posted: Mon Oct 26 21:05:10 1987 Date-Received: Thu, 29-Oct-87 04:50:00 EST Sender: news@brl-adm.ARPA Lines: 56 > Richard Tobin writes: > I never use "" for the current directory deliberately; when I encounter it > it's usually because of an error - maybe an over-ambitious C-shell > backquoted expression that didn't produce any output. This is exactly my point!!! After reading the many responses to my original invocation of this subject (many of which got off onto the wrong track), I still think that: /bin/test -d "$FOO" should return FALSE if FOO="" . And that I shouldn't have to do two tests to find out that a shell variable is a directory and is not NULL. Imagine if you will this scenario. The average programmer(a non-unix.wizard or guru) writes a shell script that will ultimately need to run as "root"(UID 0) to be used as a HOME directory remover. The script uses "awk" to pull the USER's(the one to be removed) HOME directory out of the "/etc/passwd" file and stick it in a shell variable called Home. The script will then check to see if $Home is a directory and if it is, it will remove it and all it's contents. A sample shell script follows: Home=`awk { stuff to get home } /etc/passwd` if [ -d "$Home" ]; then cd $Home : 'cd to HOME' Cwd=`/bin/pwd` : 'To fool symlinks(where are we really)' cd /tmp : 'cd to some place known' rm -rf $Cwd : 'remove the directory' rm -rf $Home : 'remove the link, if there was a link' fi Now, can you imagine what this script will do if the USER you want to delete didn't match any entries in the "/etc/passwd" file? In other words Home="" ? My guess is: YOU WOULDN'T HAVE A SYSTEM TO LOGIN TO WHEN YOU CAME TO WORK IN THE MORNING!!! Just another entry into the "Don't do this on UNIX" list. (unless ""!="." || !isadirectory("")) -franco%bbn.com@relay.cs.net ...!harvard!bbn!franco P.S. PLEASE, I don't want to hear about better ways to write such a script. Removing directories through some sort of batch job no matter how much checking and testing is done, has been deemed: "DANGER! DANGER! ALIEN LIFE FORM OF UNKNOWN ORIGIN APPROACHING FROM BEHIND THAT ROCK, WILL ROBINSON!" -Robot- "Shut up! You bubble headed boobie! -Dr. Smith- "When someone can't move any more. When someone can't talk any more. Penny! Please, don't die!" -Mr. Nobody-