Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Debugging mode – the tracing execution (option -x)

The -x option, short for xtrace or execution trace, tells the shell to echo each command after performing the substitution steps. Thus, we will see the value of variables and commands.

We can trace the execution of the Shell script as follows:

    $ bash -x hello.sh
  

Instead of the previous way, we can modify the shebang line as follows:

#!/bin/bash  -x 

Let's test the earlier debug_01.sh script as follows:

    $ bash -x hello.sh
  

Output:

    $ bash -x debug_02.sh
    + echo Hello student
    Hello student
    + date
    + echo The date is Fri May 1 00:18:52 IST 2015
    The date is Fri May 1 00:18:52 IST 2015
    + echo Your home shell is /bin/bash
    Your home shell is /bin/bash
    + echo Good-bye student
    Good-bye student
  
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content