On Fri, 1 Oct 2010 20:47:38 +0530
Nirbheek Chauhan <nirbh...@gentoo.org> wrote:

> On Fri, Oct 1, 2010 at 6:37 PM, Peter Volkov <p...@gentoo.org> wrote:
> > В Пнд, 27/09/2010 в 11:37 +0000, Dirkjan Ochtman (djc) пишет:
> >> src_compile() {
> >>       use static && sed -i -e '/^LIBS/s/LIBS = /LIBS = -static /' Makefile
> >>
> >>       emake || die "make failed"
> >>
> >>       if ! use minimal ; then
> >>               cd plugin
> >>               for i in $( ls 2>/dev/null ); do
> >
> > This is bad construction:
> > http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29
> >
> 
> A nice way around this is to do the following:
> 
>     ls -1 | while read i; do
> 
> `read` delimits on newline, so you're safe.

This strips leading and trailing whitespace.

$ touch " test1"
$ touch "test2 "
$ touch "test 3"
$ touch " test 4 "

$ ls -1 | while read i; do echo "###${i}###"; done
###test2###
###test 3###
###test1###
###test 4###

instead use:

$ ls -1 | while IFS= read i; do echo "###${i}###"; done
###test2 ###
###test 3###
### test1###
### test 4 ###

or recursively:

$ find . -type f -print0 \
  | while IFS= read -d $'\0' i; do echo "###${i}###"; done
###./ test1###
###./ test 4 ###
###./test 3###
###./test2 ###

or just make things simple on yourself :)

$ for i in *; do echo "###${i}###"; done
### test1###
###test2 ###
###test 3###
### test 4 ###


-- 
fonts, gcc-porting,             we hold our breath, we spin around the world
toolchain, wxwidgets            you and me cling to the outside of the earth
@ gentoo.org                EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662

Attachment: signature.asc
Description: PGP signature

Reply via email to