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

Re: Fascinating problem with bash



Hello Cameron, Bob,

> As soon as I read this paragraph I saw the problem. I confirmed it
> looking at the code. It's a common problem.
> 
> 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.
Okay, that is surprising indeed, as SHLVL is not being adjusted to reflect that fact, according to my findings. But thanks a bunch for pointing that out. It's surely more elegant to use this method than to write to a temporary file.

Also thanks to Bob for providing the links. Very useful, noted them down.


Thanks a lot,

// Oliver
-- 
---------------------------------------------------
DDKWizard and DDKBUILD: <http://ddkwizard.assarbad.net>

Trunk (potentially unstable) version: <http://ddkwizard.assarbad.net/trunk/ddkbuild.cmd>


Reply to: