Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #1716
| From | John Stumbles <john.stumbles@ntlworld.com> |
|---|---|
| Newsgroups | comp.os.linux.misc |
| Subject | Re: calling script function on output of find |
| Date | 2011-07-09 12:48 +0000 |
| Message-ID | <97r10bFb0uU3@mid.individual.net> (permalink) |
| References | <97g5odFp36U1@mid.individual.net> <p21ce8x6p2.ln2@perseus.wenlock-data.co.uk> |
On Tue, 05 Jul 2011 19:17:29 +0100, Dave Gibson wrote:
> find "$SOURCE_DIR" -type f -size +0 | while IFS= read -r f ; do
> process_file "$f"
> done
OK. That works.
But I don't like cargo-cult coding so let me see if I understand it.
RTFM-ing (man bash) tells me "One line is read ... and the first word is
assigned to the first name, the second word to the second name, and so
on..." and "The characters in IFS are used to split the line into words."
Also "If the value of IFS is null, no word splitting occurs."
So by setting IFS= (to null) before calling 'read' we should get the
output of find split line-by-line e.g.
dir one/file a
dir one/file b
dir two/file z
etc
which 'read' then assigns, one at a time (in the while loop), to the
variable named 'f' which then gets passed (quoted to avoid splitting) to
'process_file "$f"'.
Neat.
One question: why the -r switch ("Backslash does not act as an escape
character") to read?
--
John Stumbles
Science doesn’t understand everything.
Religion doesn’t understand anything.
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-05 10:01 +0000
Re: calling script function on output of find Joe Makowiec <makowiec@invalid.invalid> - 2011-07-05 10:20 +0000
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-09 12:04 +0000
Re: calling script function on output of find dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2011-07-05 19:17 +0100
Re: calling script function on output of find unruh <unruh@wormhole.physics.ubc.ca> - 2011-07-05 20:01 +0000
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-09 12:21 +0000
Re: calling script function on output of find Bill Marcum <bill@lat.localnet> - 2011-07-12 19:43 -0400
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-16 00:26 +0000
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-09 12:48 +0000
Re: calling script function on output of find dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2011-07-09 19:52 +0100
Re: calling script function on output of find Chris Davies <chris-usenet@roaima.co.uk> - 2011-07-07 09:37 +0100
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-08 10:02 +0000
Re: calling script function on output of find Chris Davies <chris-usenet@roaima.co.uk> - 2011-07-08 16:48 +0100
Re: calling script function on output of find unruh <unruh@wormhole.physics.ubc.ca> - 2011-07-08 17:46 +0000
Re: calling script function on output of find Chris Davies <chris-usenet@roaima.co.uk> - 2011-07-08 20:56 +0100
Re: calling script function on output of find unruh <unruh@wormhole.physics.ubc.ca> - 2011-07-08 21:14 +0000
Re: calling script function on output of find Chris Davies <chris-usenet@roaima.co.uk> - 2011-07-09 11:17 +0100
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-09 12:51 +0000
Re: calling script function on output of find Chris Davies <chris-usenet@roaima.co.uk> - 2011-07-10 10:45 +0100
Re: calling script function on output of find John Stumbles <john.stumbles@ntlworld.com> - 2011-07-10 23:14 +0000
csiph-web