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. Perhaps there is a better way of generating such a a log?
set -x
will give you what you want.Here is an example shell script to demonstrate:
This expands all variables and prints the full commands before output of the command.
output:
Another option is to put "-x" at the top of your script instead of on the command line:
(Insufficient rep to comment on chosen answer.)