home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5471 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.3 KB  |  36 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!dattier
  3. From: dattier@ddsw1.mcs.com (DWT)
  4. Subject: Re: Is there a "foreach" loop control in ksh?
  5. Message-ID: <C19v3B.6pH@ddsw1.mcs.com>
  6. Date: Fri, 22 Jan 1993 20:18:47 GMT
  7. References: <1304@alsys1.aecom.yu.edu>
  8. Organization: Contributor Account at ddsw1, Chicago, Illinois  60657
  9. Lines: 25
  10.  
  11. manaster@yu1.yu.edu (Chaim Manaster) wrote in <1304@alsys1.aecom.yu.edu>:
  12.  
  13. | I want to do a series of comands on each file in the current
  14. | directory, with some sort of "foreach" construct that will loop
  15. | over every file in some list (something like in perl), or in some
  16. | cases every file in the current directory. How would one do this in
  17. | ksh?
  18.  
  19. for variable in list
  20. do commands
  21. done
  22.  
  23. | In particular, I want to run compress on each file in the directory
  24. | that does not already end in a .Z  (dito for uncompress in
  25. | reverse).
  26.  
  27. There's no need for a for loop to call compress or uncompress separately for
  28. each file, since both can take a number of filenames as arguments.
  29.  
  30. compress !(*.Z)
  31. # in older ksh versions, compress *[!Z] *[!.]Z
  32. uncompress *.Z
  33.  
  34. David W. Tamkin   Box 59297   Northtown Station, Illinois  60659-0297
  35. dattier@ddsw1.mcs.com    CompuServe: 73720,1570    MCI Mail: 426-1818
  36.