Re: for i in $(find ...) # with whitespaces in result?
From: --==[bman]==-- (vze58jgq_at_verizon.net)
Date: 08/31/03
- Next message: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Previous message: Troll: "Re: Q: Variables - redirecting output"
- Next in thread: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Reply: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 31 Aug 2003 14:09:03 GMT
Don't be afraid to use quotes. They will protect you from shell
interpreting white spaces as field separators:
for i in "$(find . -type f)"; do
ls -l "$i"
done
It will do what you want. Be careful, however where you do your 'find'.
If directory contains thousands of files, you might get "argument list
too long" error message. Then, '-name 'something' is your friend as
part of your 'find' command...
Peter Barth wrote:
> Hi,
> How do I use the result of a find command
> in a shell script if the result can contain filenames
> with whitespaces?
> I tried a couple of things enclosing with "" and alike,
> but didn't get there. Any help appreciated.
> First try enclosed.
> ---
> (/tmp)$ ls /tmp/hatesh | more
> a
> b c
> d
> (/tmp)$ lstmp
> This works
> | /tmp/hatesh/a
> | /tmp/hatesh/b c
> | /tmp/hatesh/d
> This doesn't
> : /tmp/hatesh
> : /tmp/hatesh/a
> : /tmp/hatesh/b
> : c
> : /tmp/hatesh/d
> This doesn't either
>
>> /tmp/hatesh /tmp/hatesh/a /tmp/hatesh/b c /tmp/hatesh/d
>
> (/tmp)$ cat lstmp
> #!/bin/sh
> echo "This works"
> for file in /tmp/hatesh/*; do
> echo "| " $file
> done
> echo "This doesn't"
> for file in $( find /tmp/hatesh ); do
> echo ": " $file
> done
> echo "This doesn't either"
> for file in "$( find /tmp/hatesh )"; do
> echo "> " $file
> done
> ---
> Cheers
> - Peter
--
__ _
/ / (_)__ __ ____ __
/ /__/ / _ \/ // /\ \ /
/____/_/_//_/\_,_//_\_\ Life is what you make of it...
- Next message: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Previous message: Troll: "Re: Q: Variables - redirecting output"
- Next in thread: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Reply: Chris F.A. Johnson: "Re: for i in $(find ...) # with whitespaces in result?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|