CHAPTER 10Piping Input to read

This chapter deals with a gotcha that I came across while porting a script from ksh to bash. It was a gotcha only because at the time I wasn't aware of a fairly crucial difference in the behavior of the two shells. In both pdksh and bash, the last command of a pipeline is performed in a subshell. This means that a variable assigned within the subshell is not available to the parent shell. In ksh, the last command of a pipeline is executed in the original shell.

This isn't an issue when using the pipe to set a variable, but if the result of a pipe is sent to a loop structure that then populates variables you will use later, that is more of a problem. Once the loop completes, the variables you were going to rely ...

Get Expert Shell Scripting now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.