home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5521 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.8 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!darwin.sura.net!newsserver.jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uknet!sni!wstuart!stephen
  2. From: stephen@wstuart
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: help with a script files
  5. Message-ID: <1993Jan28.152735.2246@sni.co.uk>
  6. Date: 28 Jan 93 15:27:35 GMT
  7. References: <1993Jan26.203636.7606@aruba.uucp>
  8. Sender: news@sni.co.uk (Usenet News)
  9. Reply-To: stuart@siesoft.co.uk
  10. Organization: Siemens Nixdorf Information Systems Ltd.
  11. Lines: 50
  12. X-Newsreader: Tin 1.1 PL4
  13.  
  14. rickt@aruba.UUCP (Rickey Thomas Tom) writes:
  15. : I a working on a script that basicaly moves files from a subdirectory to
  16. : a current directory.
  17. : The problem is that if there are no files in the subdirectory, the script
  18. : terminates and returns an error code that says that no files were found.
  19. : I tried    if ( -e "<dir x>/* ) then
  20. :                 .....
  21. : but this does not work either
  22.  
  23. It appears that you are using csh for your scripts.
  24.  
  25. In my experience csh is harder to use, more bug-ridden
  26. and less portable than sh and so recommend that you use
  27. sh for your scripts.  (By all means use, as I do, csh
  28. for an interactive shell.)
  29.  
  30. In sh, you can do exactly as you tried (obviously the
  31. sytax is different):
  32.  
  33.     if test -f <dir x>/*
  34.     then
  35.     # there exist files in <dir x>
  36.     else
  37.     # there are no files in <dir x>
  38.     fi
  39.  
  40. In csh, if you must:
  41.  
  42.     set nonomatch
  43.     if ( -e <dir x>/* ) then
  44.     # there exist files
  45.     else
  46.     # there don't
  47.     endif
  48.  
  49.     Note: 1. this still fails if <dir x> doesn't exist
  50.       2. "-e <dir x>/*" returns true for both directories
  51.          and files
  52.  
  53.  
  54. Stuart
  55. -
  56. --
  57. S I E M E N S  Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
  58. -------------  Phone: + 44-344-850892          Email: stuart@siesoft.co.uk
  59. N I X D O R F  - Never let ignorance stand in the way of a good argument -
  60.