svn commit: r341803 - head/libexec/rc

Simon J. Gerraty sjg at juniper.net
Wed Dec 12 02:07:39 UTC 2018


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 at freebsd.org> wrote:
> On Tue, Dec 11, 2018 at 2:42 PM Devin Teske <dteske at 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.


More information about the svn-src-head mailing list