set -x enables a mode of the shell where all executed commands are printed to the terminal.

[ "$DEBUG" == 'true' ] && set -x
$ ./your-script DEBUG=true

source

Example

#!/bin/bash

set -x  # enable printing of commands
git log -n 1 HEAD | cat
ruby -v
bundle -v
set +x  # disable printing of commands

# ...

source