---
title: "Print Commands in Bash Script"
date: 2018-11-24T15:38:11.000Z
author: Z.SHINCHVEN
tags: [Bash]
canonical: https://atlassc.net/2018/11/25/print-commands-in-bash-script
---
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 needs to be enabled by adding [The Set Builtin](https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html).


## 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

```bash
bash -v <YOUR_SCRIPT>
```

### Use in Script

```bash
#!/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

```bash
bash -x <YOUR_SCRIPT>
```

### Use in Script

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