home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10766 < prev    next >
Encoding:
Text File  |  1992-09-07  |  1.3 KB  |  50 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!mcsun!sunic!psinntp!psinntp!sadtler!rick
  3. From: rick@sadtler.sadtler.com (Rick Morris)
  4. Subject: Nothing is a directory?
  5. Message-ID: <1992Sep3.231718.16061@sadtler.com>
  6. Sender: rick@sadtler.com (Rick Morris)
  7. Organization: Sadtler Research Laboratories
  8. Date: Thu, 3 Sep 1992 23:17:18 GMT
  9. Lines: 39
  10.  
  11. I came across an interesting situation I thought I'd throw
  12. out for discussion.
  13.  
  14. In a Bourne script, I ask the user for the name of a
  15. directory.  If the user enters return, the variable
  16. contains nothing.  Then I test the results.
  17.  
  18. #!/bin/sh
  19. #
  20. read dir
  21. if test -d "$dir"; then
  22.     echo "Yes, a directory."
  23. else
  24.     echo "No, not a directory."
  25. fi
  26. #
  27. exit 0
  28. #
  29.  
  30. Well guess what.  On our SUN (4.1.3), nothing is
  31. a directory.  That little script results in:
  32.  
  33. Yes, a directory.
  34.  
  35. On our SGI, nothing is not a directory.  That
  36. little script results in:
  37.  
  38. No, not a directory.
  39.  
  40. So, who is right?  Is nothing a directory?
  41. I read in the man page that -d returns true if argument
  42. exists and is a directory, so I would assume that the
  43. null argument should be false like the SGI.
  44.  
  45. -Rick.
  46. -- 
  47. Rick Morris                            Email:  rick@sadtler.com
  48. Sadtler Research Labs, Philadelphia   -But I speak for myself
  49. ---------------------------------------------------------------
  50.