Debug Bash Script

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 Debug bash script with -x option from the command line

bash -x Bash_script_name

Or

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:

Debug Bash Script

Conclusion

Thought the article, you can use Debug Bash Script as above. I hope will this your helpful. More details refer to Bash script.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.