Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #1655
| From | Chris Davies <chris-usenet@roaima.co.uk> |
|---|---|
| Newsgroups | comp.os.linux.misc |
| Subject | Re: calling script function on output of find |
| Date | 2011-07-07 09:37 +0100 |
| Organization | Roaima. Harrogate, North Yorkshire, UK |
| Message-ID | <mr7ge8xnbe.ln2@news.roaima.co.uk> (permalink) |
| References | <97g5odFp36U1@mid.individual.net> |
John Stumbles <john.stumbles@ntlworld.com> wrote:
> This seems to be a limitation of the "for f in ..." construct and I
> should probably be doing something else - but what?!
The other posters have given correct constructs, but I haven't seen any
of them explain why theirs would work but yours doesn't.
It's all to do with quoting. If you double-quote a "$variable" then the
spaces that it may contain are kept as part of the item. If you don't
quuote $variable then it is subject to splitting on whitespace. Single
quotes around '$variable' shop the string being expanded at all (the
string remains as a literal - in this example being 9 characters long).
mkdir 'one' 'two' 'one two'
touch 'one/first' 'two/second' 'one two/others'
NUMBERS='one two'
ls $NUMBERS # Lists two directories 'one' and 'two'
ls "$NUMBERS" # Lists single directory 'one two'
ls '$NUMBERS' # Fails as '$NUMBERS' does not exist
Coming back to your specific example, part of the answer to your question
is to quote "$SOURCE_DIR" within your 'find' construct. However,
the 'for' loop will still break when 'find' itself returns pathnames
containing spaces - and this will happen because you have already said
that $SOURCE_DIR does contain spaces. At that point you need to invert the
construct to avoid 'for' having the opportunity to split on whitespace.
Chris
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