Get text output from shell script commands on screen while execution

You can get the shell to echo everything it is doing, by running the following command:

sh -x yourscript

Or you can add this as the first command in the script:

set -x

It can get a bit too verbose, though. It's OK for debugging, but if you want selective output it would be best to do it yourself with carefully places echo commands.


You can tee commands to send a copy of standard output to a file, and you can use the current terminal as that output file. As you can see in the following, it will print twice if you don't use the output for anything, and once if standard output is swallowed by doing something to it:

$ echo foo | tee -a /dev/tty
foo
foo
$ echo foo | tee -a /dev/tty | grep bar
foo