Linux Know-How provides a collection of introductory texts on often needed Linux skills. |
Home Bash Guide for Beginners The Bash environment Bash options | ||||||
See also: Debugging Bash scripts | ||||||
Search the VIAS Library | Index | ||||||
Bash optionsDisplaying optionsWe already discussed a couple of Bash options that are useful for debugging your scripts. In this section, we will take a more in-depth view of the Bash options. Use the -o option to set to display all shell options:
See the Bash Info pages, section -> for a description of each option. A lot of options have one-character shorthands: the xtrace option, for instance, is equal to specifying set -x.Changing optionsShell options can either be set different from the default upon calling the shell, or be set during shell operation. They may also be included in the shell resource configuration files. The following command executes a script in POSIX-compatible mode:
For changing the current environment temporarily, or for use in a script, we would rather use set. Use - (dash) for enabling an option, + for disabling:
The above example demonstrates the noclobber option, which prevents existing files from being overwritten by redirection operations. The same goes for one-character options, for instance -u, which will treat unset variables as an error when set, and exits a non-interactive shell upon encountering such errors:
This option is also useful for detecting incorrect content assignment to variables: the same error will also occur, for instance, when assigning a character string to a variable that was declared explicitly as one holding only integer values. One last example follows, demonstrating the noglob option, which prevents special characters from being expanded:
|
||||||
Home Bash Guide for Beginners The Bash environment Bash options |