Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2018 18:07:26 -0800
From:      "Simon J. Gerraty" <sjg@juniper.net>
To:        <cem@freebsd.org>
Cc:        Devin Teske <dteske@freebsd.org>, src-committers <src-committers@freebsd.org>, <svn-src-all@freebsd.org>, <svn-src-head@freebsd.org>, <sjg@juniper.net>
Subject:   Re: svn commit: r341803 - head/libexec/rc
Message-ID:  <46440.1544580446@kaos.jnpr.net>
In-Reply-To: <CAG6CVpXkQ0fZCj=-nhmJzbju5suMxY=giRoSdg6LXeWO-i3E8A@mail.gmail.com>
References:  <201812110138.wBB1cp1p006660@repo.freebsd.org> <2a76b295-b2da-3015-c201-dbe0ec63ca5a@FreeBSD.org> <98481565-CDD7-4301-B86B-072D5B984AF7@FreeBSD.org> <dafbcc18-146f-2e4f-e1e9-346d7c05b096@FreeBSD.org> <CANCZdfqtyvxCBwdwDQ4Raeven2LmaPd3C-c---pVFhHDWBKfxA@mail.gmail.com> <CAG6CVpVtWL448-pxW9EK7SEe7Cfk1mkCvPNmtE=YuFWM3Bn0tA@mail.gmail.com> <C3D7104B-2A6F-4BF0-865C-B941651EDD1A@FreeBSD.org> <CAG6CVpXVNYyQmdZcADBE_CJB1toKPdnHZEfY54Do-OcYeDAzJg@mail.gmail.com> <917251B0-00E0-47E2-B6FB-568EDB9ED781@FreeBSD.org> <CAG6CVpXkQ0fZCj=-nhmJzbju5suMxY=giRoSdg6LXeWO-i3E8A@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Just caught the tail of this thread so sorry for
chiming in from the peanut gallery...

	blah | while read x; do ...; done

behaves very differently to the for loop variant in that the body of the
loop runs in a sub-shell and thus cannot affect the outer scope.
In many cases that's exactly what you want.
Sometimes though, it isn't.

Conrad Meyer <cem@freebsd.org> wrote:
> On Tue, Dec 11, 2018 at 2:42 PM Devin Teske <dteske@freebsd.org> wrote:
> > In that case, would it be appropriate to say that:
> >
> >         blah | while read x; do ...; done
> >
> > Is always more efficiently written as:
> >
> >         IFS=$'\n'
> >         for x in $( blah ); do ...; done
> 
> I don't know.  The suggestion came from jilles@, who is much more
> familiar with sh(1) than I am.
> 
> My understanding is that it's important that 'set -o noglob' is set,
> or else 'blah' lines that include globs may be evaluated against the
> filesystem.  There is also a caveat if 'blah' is the 'set' command, or
> similar, in that IFS' own value itself will be split across multiple
> for loop iteration 'x' values ("IFS='", "'").
> 
> I would hesitate to say "always" given my limited understanding of the
> shell, but it might be true.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46440.1544580446>