23.2. The set command

The set command can be used as an aid to debugging. Here are set ’s most useful debugging options.

set -n Read commands but do not execute them
set -v Display all lines as they are read
set -x Display all commands and their arguments

To turn a set option off simply substitute the sign with the +. I always think that it should be the other way round, + to turn it off and to turn it on, but that’s just me.

You can use set at the top of your script to enable it and then disable it when the script finishes, or you can stick set in just a particular block statement that is giving you problems.

Let’s see set in action. Here’s a little script that holds some names in a variable list. The user inputs a name, a for loop then loops ...

Get Linux and Unix Shell Programming 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.