Debugging mode - displaying commands (option -v)

The -v option tells the shell to run in verbose mode. In practice, this means that the shell will echo each command prior to executing the command. This will be useful in locating the line of script that has created an error.

We can enable the script execution with the -v option as follows:

    $ bash -v hello.sh
  

Another way is by modifying the shebang line as follows:

#!/bin/bash  -v

In this case, we can run the script with the -v option as follows:

    $ chmod u+x hello.sh
    $ ./hello.sh
  

Let's write the debug_02.sh script as follows:

#!/bin/bash 
echo "Hello $LOGNAME" 
echo "Today is `date` 
echo "Your present working directory is $PWD 
echo Good-bye $LOGNAME 

Save the file, give the permission to execute, ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.