How to echo shell commands as they are executed
Asked 07 September, 2021
Viewed 306 times
  • 61
Votes

In a shell script, how do I echo all shell commands called and expand any variable names?

For example, given the following line:

ls $DIRNAME

I would like the script to run the command and display the following

ls /full/path/to/some/dir

The purpose is to save a log of all shell commands called and their arguments. Is there perhaps a better way of generating such a log?

14 Answer