How Debug a Shell Script

It is really simple debug a shell script.  For instance, if you need to trace all the code, you just need insert the code “set -x” into the code.
Let me show you an example:

#!/bin/bash
set -x

num=3

if [ $num -le 1 ]
then
   echo "if"
else
   echo "else"
fi

OUTPUT
rcls@rcls-notebook:~$ ./test.sh
+ num=3
+ ‘[‘ 3 -le 1 ‘]’
+ echo else
else