"Derek D. Martin" <[EMAIL PROTECTED]> writes:
> At some point hitherto, Kevin D. Clark hath spake thusly: > > In general, the inner part of the loop is run in a sub-shell. > > Not exactly... it's more subtle even than that. For example: Yes, my language could have been a little tighter there. "In general" isn't right; "in general, when you're using a loop and doing any sort of file redirection, the loop might be implemented as a subshell" is more correct. > Certain kinds of things trigger the shell to use a subshell for loops. Yes. > One is, as in the example above, piping the output of a process into > another command. Another is if you redirect the output of the loop > into a file, as in > > done >> $ouputfile > > In the former case, I believe it does so because the shell which the > script is running in must No, not "must", but instead "the shell happens to implement it this way". Implementing this in other ways would be a lot more difficult, and so this behavior has come to be viewed as "reasonable". Of course, sometimes this isn't the desired behavior, and you have to take other steps to get what you want (like use Perl...). > first fork a process to generate the output, > and fork a second process (a shell) to feed the output of that command > to through a pipe (as in pipe(2)). I believe this is necessary > because the stdout and stdin of the processes which the shell runs are > not the same as those of the shell itself. Well, in the cases that we are discussing, stdin and stdout are different, but stderr is the same. > I'm not quite positive on > that, and hopefully someone will correct me if I'm mistaken. The > latter case would essentially be the same thing; the shell the loop is > running in has a different stdout than the shell script itself, so it > must... Again, not "must". I'm sure you know what I mean. Regards, --kevin -- Kevin D. Clark (CetaceanNetworks.com!kclark) | Cetacean Networks, Inc. | Give me a decent UNIX Portsmouth, N.H. (USA) | and I can move the world alumni.unh.edu!kdc (PGP Key Available) | ***************************************************************** To unsubscribe from this list, send mail to [EMAIL PROTECTED] with the text 'unsubscribe gnhlug' in the message body. *****************************************************************
