$ sh -xv program_name 2>&1 | more"-xv" switch tells shell to display and execute the shell script one line at a time. As it is executing, it will also show the actual command being executed (leading by a plus sign). So, you will know exactly if the shell script did what you want it to do.
2>&1 is applied to the sh -xv program_name process, and it dups stderr from stdout. The stdout was already referring to the input end of the pipe, so both the standard error and standard output of the sh will get written to the pipe. If 2>&1 is omitted, the standard output will still be displayed one page at a time by more, but the standard error message will be randomly written to the screen.
The corresponding notation for the C-shell is
% sh -xv program_name |& more

bsy@cse.ucsd.edu, last updated