home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!mcdchg!laidbak!katzung
- From: katzung@i88.isc.com (Brian Katzung)
- Subject: Re: Is there a "foreach" loop control in ksh?
- Message-ID: <1993Jan22.173754.17016@i88.isc.com>
- Sender: usenet@i88.isc.com (Usenet News)
- Nntp-Posting-Host: laitnite.i88.isc.com
- Organization: Interactive Systems Corporation, Naperville, IL
- References: <1304@alsys1.aecom.yu.edu>
- Date: Fri, 22 Jan 1993 17:37:54 GMT
- Lines: 41
-
- In article <1304@alsys1.aecom.yu.edu> manaster@yu1.yu.edu (Chaim Manaster) writes:
- |I want to do a series of comands on each file in the current
- |directory, with some sort of "foreach" construct that will loop
- |over every file in some list (something like in perl), or in some
- |cases every file in the current directory. How would one do this in
- |ksh?
-
- For every file except, regardless of type, try:
-
- for file in `find . -print -prune`
- do
- ...
- done
-
- For regular files, use:
-
- for file in `find ..?* .[!.]* * -prune -type f -print 2> /dev/null`
- do
- ...
- done
-
- You can also use the one above without the "-type f" if you want
- all types of files, but don't want ./ in front of each one. Just
- omit the "." patterns if they are excessive for your needs.
-
- |In particular, I want to run compress on each file in the directory
- |that does not already end in a .Z
-
- find ..?* .[!.]* * -prune ! -type f -name '*.Z' -print 2> /dev/null |
- xargs compress
-
- |(dito for uncompress in
- |reverse).
-
- find ..?* .[!.]* * -prune -type f -name '*.Z' -print 2> /dev/null |
- xargs uncompress
-
- There is nothing ksh-specific here BTW, so these should work in sh just
- as well.
-
- -- Brian Katzung katzung@i88.isc.com
-