Shell – Get text output from shell script commands on screen while execution

echoscriptingshell

Consider the following shell script

val=($ls)

The ls does not not give any shell text output. Now, how do we get output text on screen while the command is being executed?

I can print the value of val to get the output, but using echo is not the point. So, using the following line is not the case

echo $val

So, in nutshell, how do I get the output of current command being executed in shell simultaneous as if you were executed the command by itself?

Best Answer

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.

Related Question