set -xyou can turn on tracing, so that every command is printed before being executed. In bash, you can also customize the output prefix by setting the
PS4variable. The default is
PS4='+ '. Here is an example. I wanted to "profile" a deployment script, to see why it took so long. Ordinarily, I might have sprinkled it with
datecalls. Instead, I merely added
set -x PS4='+\t 'near the top.
\tstands for time stamp. (The script was already using bash explicitly, as opposed to
/bin/sh.) That way, every line is prefixed by a time stamp, and the logs could easily be analyzed to find a possible performance bottleneck.