Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: Steven J Long <slong@...>
Subject: Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Date: Tue, 29 May 2012 14:50:19 +0100
Michał Górny wrote:

> +  find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; 
..
> +	rm -f "${f}" || die
..
> +  done

Don't pipe to read like that; it means the final command is in a subshell 
and "die is /not/ guaranteed to work correctly if called from a subshell 
environment."[1]

More seriously, the script doesn't actually get the correct filenames, 
despite being written to handle any filename.
eg:
$ touch $'  foo bar \n\t  '
$ while read -r -d '' f; do echo "'$f'"; done < <(find . -type f -print0)  
'./  foo bar'

You do it like this:

while read -rd ''; do
   f=$REPLY;
   ..
done < <(find "$D" -type f -name '*.la' -print0)

eg:
$ while read -rd ''; do f=$REPLY; echo "'$f'"; done < <(find . -type f -
print0)                                                                                           
'./  foo bar                                                                                     
          '

Or use: while IFS= read -rd '' f; do .. if you prefer.
See: help read # in a terminal.

It's called 'Process Substitution' if anyone wants to read about it in
man bash. The classic example with find is to get the list in an array:
arr=()
while read -rd ''; do
  arr+=("$REPLY")
done < <(find "$dir" -type f .. -print0)

(perhaps conditionally though that's usually better done within find
 which can later be handled on a per-file basis, or passed to:
foo "${arr[@]}"

..or if you just want to know whether there is a matching file:
if read -rd '' < <(find . -type f -print0); then
   something matched
else nothing did
fi

They're both things I came up with a few years ago when I was learning
from #bash, which you are in dire need of, based on reading git-2.eclass.

[1] http://dev.gentoo.org/~ulm/pms/head/pms.html#x1-12600011.3.3
(11.3.3.6)
-- 
#friendly-coders -- We're friendly, but we're not /that/ friendly ;-)




Replies:
Re: Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
-- Michał Górny
Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
-- Steven J Long
References:
[PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
-- Michał Górny
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Next by thread:
Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Previous by date:
RFC: trivial chromium.eclass patch
Next by date:
Re: RFC: Enable FEATURES="userpriv usersandbox" by default?


Updated Jun 29, 2012

Summary: Archive of the gentoo-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.