On Fri, Jan 19, 2001 at 12:45:11PM -0500, [EMAIL PROTECTED] wrote:
 
>   regarding why there is this odd feature about variable scope in
> the bash shell, i suspect it's because it has the same feature as
> the korn shell regarding variables and loops.
> 
>   in a normal loop in ksh, all variables are at the current level
> and behave normally.  however, the instant you incorporate I/O
> redirection into a loop with one of:
> 
>       cmd | loop ...
>       loop ... | cmd
>       loop ... > file
> 
> and so on, things change. the loop commands will now (at least in ksh)
> be executed in a pseudo-subshell, not a real subshell.
> 
>a pseudo-subshell has read access to all variables at the current
>level, but not write access (hence the "pseudo" qualifier).  that
>would certainly explain what's happening in the example that's been
>presented. 
> 
> comments?

I posted the original question. I didn't realize the pipe was spawning
a subshell or pseudo-subshell. So now it makes sense. To a point.
There are times it would seem desirable to have read/write access to
variables in these circumstances. So is this a 'feature', or is it
technically difficult to accomplish, or is there a better way? 

To work around this, I am writing the variables to disk before exiting
the loop, then reading them back in. This 'works', though seems
awkward. I realize too there are other languages that can deal with
this. Just curious.

-- 
Hal B
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
--



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to