How to debug a bash script? you can investigate the causes of the problems so you can apply fixes. Yeah, I will guide you turn on debug bash script. Bash script the essential for DevOps Roles.
Debug bash script using various methods.
Running a bash script with -x option from the command line
bash -x Bash_script_name
bash -xv Bash_script_name
Using shebang line in debug mode
#!/bin/bash -x echo "welcome to DevopsRoles.com"
Use set builtin command
Bash script can tun on or off using set command
- Display commands and their arguments: set -x
- Display shell input lines: set -v
- This may be used to check a shell script for syntax errors. To read commands but do not execute them: set -n
#!/bin/bash ## Turn on debug mode ## set -x echo "Users currently on the machine" w ## Turn OFF debug mode ## set +x
The screen output terminal:
Thought the article, you can use Debug Bash Script as above. I hope will this your helpful. More details refer to Bash script.