On Sat, Aug 05, 2006 at 03:45:26PM +1000, John O'Hagan wrote:
> Hi,
>
> I keep running into this particular gap in my scripting, and hope someone can
> clear it up for me.
>
> FILES=$( ls SOMEWHERE ) #or find or grep, etc
>
> for FILE in $FILES; do SOMETHING; done
>
> I often find that if there are spaces in the names of anything in $FILES, the
> execution of SOMETHING occurs separately for each word in the name, producing
> unexpected results.
>
> Quoting doesn't seem to help. Are there ways to deal with this?
>
> Thanks,
>
Hi John,
here are two examples. #1 should work, while #2 should not.
ls | while read FILE; do
test -e "$FILE" || echo opps $FILE;
done
ls | while read FILE; do
test -e $FILE || echo opps $FILE;
done
cheers,
Kev
--
| .''`. == Debian GNU/Linux == | my web site: |
| : :' : The Universal | debian.home.pipeline.com |
| `. `' Operating System | go to counter.li.org and |
| `- http://www.debian.org/ | be counted! #238656 |
| my keysever: pgp.mit.edu | my NPO: cfsg.org |
signature.asc
Description: Digital signature

