SH bahaviour to not fork a subshell after " | while read "
Configuration Information [Automatically generated, do not change]: Machine: powerpc OS: aix5.1 Compiler: xlc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' -DCONF_OSTYPE='aix5.1' -DCONF_MACHTYPE='powerpc-ibm-aix 5.1' -DCONF_VENDOR='ibm' -DLOCALEDIR='/opt/freeware/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I ./include -I./lib -I/opt/freeware/include -O2 uname output: AIX tsm 1 6 00C530EB4C00 Machine Type: powerpc-ibm-aix5.1 Bash Version: 3.0 Patch Level: 16 Release Status: release Description: In bash mode, variable are lost after a while loop: bash-3.00# T=toto ; du | while read a ; do T=$a ; done ; echo $T toto I can keep then a little using parenthesis: bash-3.00# T=toto ; du | (while read a ; do T=$a ; done ; echo $T) ; echo $T 1489648 . toto Repeat-By: bash-3.00# T=toto ; du | while read a ; do T=$a ; done ; echo $T toto Fix: May be starting in "sh" mode and/or posix mode should behave like a real bourne shell bash-3.00# /usr/bin/sh # T=toto ; du | while read a ; do T=$a ; done ; echo $T 1489632 . # exit bash-3.00# ~
Re: SH bahaviour to not fork a subshell after " | while read "
Thanks ! 2012/6/1 Greg Wooledge : > On Fri, Jun 01, 2012 at 10:53:22AM +0200, freD wrote: >> bash-3.00# T=toto ; du | while read a ; do T=$a ; done ; echo $T >> toto > > http://mywiki.wooledge.org/BashFAQ/024 > > Quick answer: while read ... done < <(some command) > Portable version: mkfifo fifo; some command > fifo & ...