Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

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

Using the set command

Most of the time, we invoke the debugging mode from the first line of script. This debugging mode will remain active until the last line of code. But many times, we may need to enable debugging for a particular section of script. By using the set command, we can enable and disable debugging at any point in our shell script:

    set -x
    section of script
    set +x
  

Consider the following script:

#!/bin/bash 
 
str1="USA" 
str2="Canada"; 
 
[ $str1 = $str2 ] 
echo $? 
 
Set -x 
 
[ $str1 != $str2 ] 
echo $? 
 
[ -z $str1 ] 
echo $? 
 
Set +x 
 
[ -n $str2 ] 
echo $? 
 
Exit 0 

In this case, the debugging will be enabled after the set -x and will be disabled immediately after the set +x.

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