[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fascinating problem with bash



Cameron Hutchison wrote:
> This construct:
> 
> some_cmd | while read var ; do
>     OTHER_VAR=...
> done
> 
> will result in OTHER_VAR being unset at the completion of the loop. That
> is because the while command is on the right-hand side of the pipe
> meaning it runs in a subshell. At the end of the while loop, the
> subshell exits and any vars it sets will go away with it.

And just to add, here are some references for further information.

  http://mywiki.wooledge.org/BashFAQ/024
  http://mywiki.wooledge.org/SubShell

And it is FAQ E4 in the Bash FAQ.

  ftp://ftp.cwru.edu/pub/bash/FAQ

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: