We can transcript and run multiple commands in one single bash script file, but it won’t print the command you wrote in script by default.
Whereas, printing commands in script is supported, it just need to be enabled by adding The Set Builtin.

verbose

Print shell input lines as they are read.

Value of variables won’t be print out, it’s safe in this way to protect your secrets like password or token.

Use in Command Line

1
bash -v <YOUR_SCRIPT>

Use in Script

1
2
3
#!/usr/bin/env bash
set -v
## ... this rest of your scripts

xtrace

Print a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and their arguments or associated word lists after they are expanded and before they are executed. The value of the PS4 variable is expanded and the resultant value is printed before the command and its expanded arguments.

I do NOT recommend any one to use xtrace in production, for your secrets passed in variables like password or token might be cached in log or somewhere else, they might be leaked.

Use in Command Line

1
bash -x <YOUR_SCRIPT>

Use in Script

1
2
3
#!/usr/bin/env bash
set -x
## ... this rest of your scripts