[LEDE-DEV] [patch master 13/15] To read lines rather than words, pipe/redirect to a 'while read' loop

Oswald Buddenhagen oswald.buddenhagen at gmx.de
Sat Oct 1 02:09:48 PDT 2016


On Sat, Oct 01, 2016 at 12:44:36AM +0200, Lars Kruse wrote:
> Am Fri, 30 Sep 2016 22:02:27 +0200 schrieb Jan-Tarek Butt <tarek at ring0.de>:
> 
> > ---
> >  scripts/deptest.sh | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/scripts/deptest.sh b/scripts/deptest.sh
> > index 8c859ef..0b0e7a9 100755
> > --- a/scripts/deptest.sh
> > +++ b/scripts/deptest.sh
> > @@ -86,9 +86,9 @@ test_package() # $1=pkgname
> >  	[ -n "$pkg" -a -z "$(echo "$pkg" | grep -e '/')" -a "$pkg" != "." -a "$pkg" != ".." ] || \ die "Package name \"$pkg\" contains illegal characters"
> >  	local SELECTED=
> > -	for conf in $(grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,'); do
> > +	while IFS= read -r conf; do
> >  		grep "$conf=" .config > /dev/null && SELECTED=1 && break
> > -	done
> > +	done < "$(grep CONFIG_PACKAGE tmp/.packagedeps | grep -E "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,')"
> 
> Is this really doing what it looks like?
>   ... < "$(command)"
> This should try to read from a file named like the output of "command" - and
> not the lines of command's output.
> 
> I guess, the following approach should do the right thing:
> 
>   grep CONFIG_PACKAGE tmp/.packagedeps | grep -E > "[ /]$pkg\$" | sed -e 's,package-$(\(CONFIG_PACKAGE_.*\)).*,\1,') | while IFS= read -r conf; do
>     ...
>   done
> 
this won't work, because it makes the loop body a subshell, and thus the
assignment of SELECTED will get lost.

to achieve the goal with minimal effort, adding

  local IFS=$'\n'

prior to the loop should be sufficient.

ps: please configure your mailer to not wrap quotes.



More information about the Lede-dev mailing list