[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing paths with spaces from one command to another
From: |
Greg Wooledge |
Subject: |
Re: Passing paths with spaces from one command to another |
Date: |
Tue, 10 Mar 2009 08:51:21 -0400 |
User-agent: |
Mutt/1.4.2.2i |
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.)