Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 May 1998 22:36:54 -0400 (EDT)
From:      "John W. DeBoskey" <jwd@unx.sas.com>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Unexpected behavior from pdksh
Message-ID:  <199805080236.AA16907@mozart>

next in thread | raw e-mail | index | archive | help
Hi,

The following is on 3.0-CURRENT using pdksh.

Given the following sample Korn Shell script:

export FOO=foo
echo $FOO

echo bar | while read var; do
   export FOO=$var
   echo $FOO
done

echo $FOO

The output is:
foo
bar
foo

where I was expecting:
foo
bar
bar


  If I put the value 'bar' in a file and change the while
loop to:

echo bar > varfile
while read var; do
   export FOO=$var
   echo $FOO
done < varfile

  I get the expected reult with the above.

  It seems that the pipe '|' is causing the 'while read var' to
execute in a subshell. Does anyone know of a way to make this
work the way I am expecting it to? fyi: this seems to work ok
under hpux.

Thanks,
John

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



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