RE: [ILUG] Bash bug or weird rule?

From: McLoughlin, Mark (mark.mcloughlin at domain intel.com)
Date: Thu 20 Jul 2000 - 15:58:23 IST


> > #!/bin/bash
> > export VAR="joe"
> > VAR=$(
> > cat test | while read blah
> > do
> > echo $blah
> > done
> > )
> > echo $VAR
> >
> > That's the work around
>
        Sorry, that's not specifically what I was trying to do. The script
was just to find exactly what the inconsistency between bash and ksh was.

        It's more like

        cat test | while read aa ; do
                eval $aa
        done

        where test contains
        VAR1=blah
        VAR2=de
        VAR3=blah
        and still have VAR1 VAR2 VAR3 available with in the rest of the
script

> or just:
>
> echo "Why will this work?" | { read var; echo $var; }
>
> ie group the commands using {} or ()
>
>
> re mark's original problem, one solution (based on his sample code)
> would be something like:
>
> #!/bin/bash
> export VAR="blank"
> echo ----- $VAR -----
> grep VAR t.tmp | awk '{print $2}' | {
> while read blah ; do
> export VAR=$blah
> echo ----- $VAR -----
> done
> echo ----- $VAR ----- # Should $VAR be "variable2" or "blank"
> }
>
        Sweet, except this is inside a function. And even if it wasn't, I
really don't want to have half a 800 line script( not written by me )
hanging off the one pipe.

        It's no big deal - just a ksh script I wanted to use on a linux box
and this was the big bash/ksh inconsistancy I came across. So I I just
downloaded ksh.

        It's bugging me though, why does bash fork off a process in a _only_
pipline and not from stdin. It's just a different file descriptor right?
Actually why does it fork off a process at all?

> or use perl ...
>
        That would be my first choice, as always. But I decided It was about
time I stopped shying away from shell in favour of Perl every time shell
gave me a bit of hassle - I wonder how long that'll last ;¬)

> -Tarlach
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription
> information.
> List maintainer: listmaster at domain linux.ie



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:56 GMT