Bash Getting started with Bash Hello World in "Debug" mode

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

$ cat hello.sh 
#!/bin/bash 
echo "Hello World"
$ bash -x hello.sh 
+ echo Hello World
Hello World

The -x argument enables you to walk through each line in the script. One good example is here:

$ cat hello.sh
#!/bin/bash 
echo "Hello World\n" 
adding_string_to_number="s"
v=$(expr 5 + $adding_string_to_number) 

$ ./hello.sh 
Hello World

expr: non-integer argument

The above prompted error is not enough to trace the script; however, using the following way gives you a better sense where to look for the error in the script.

$ bash -x hello.sh 
+ echo Hello World\n
Hello World

+ adding_string_to_number=s
+ expr 5 + s
expr: non-integer argument
+ v=


Got any Bash Question?