O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required