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

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
    $ ./

Let's write the script as follows:

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.