> for ... > do > variable=some > done | ... > echo $variable The problem is that `variable' is being set in a forked subshell. I don't know of any simple way around this.