On Tue, Mar 10, 2009 at 02:31:06PM +0200, Angel Tsankov wrote:
> What if the second command is a function defiend in a shell script, or a
> bash built-in command?
I assume this is related to Mike's earlier answer of:
find . -print0 | xargs -0 ls
You can use a while read loop:
find . -print0 | while read -r -d ''; do
myfunc "$REPLY"
done
If you need to set variables inside the loop and use them afterward, then
you must avoid the subshell:
while read -r -d ''; do
myfunc "$REPLY"
done < <(find . -print0)
(See http://mywiki.wooledge.org/BashFAQ/024 )
Note that if you use a variable other than REPLY in your read command,
you must also set IFS to an empty value; otherwise you lose all leading
whitespace.
Or you could load the output of find into an array (using a loop) and
then iterate over the array. (See http://mywiki.wooledge.org/BashFAQ/095
and http://mywiki.wooledge.org/BashFAQ/005 etc.)