The key is that pipeline commands run in subshells. The 'read output | echo $output' part runs in a subshell where output=5, but this doesn't affect the parent shell where output=1. The final 'echo $output' is in the parent shell, so it prints 1. The pipe from echo $output goes nowhere (read already consumed its input), so output is just '1'.