set

From RaySoft

Set or unset values of shell options and positional parameters.[1]

Using + rather than - causes these flags to be turned off.[1]

Documentation

Further Information

Syntax

set [PARAMETER ...] [ARGUMENT ...]

Parameters

-e
Exit immediately if a command exits with a non-zero status.
-f
Disable file name generation (globbing).
-o NAME
Set the variable corresponding to NAME:
errexit
Same as -e.
noglob
Same as -f.
nounset
Same as -u.
pipefail
The return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status.
verbose
Same as -v.
xtrace
Same as -x.
-u
Treat unset variables as an error when substituting.
-v
Print shell input lines as they are read.
-x
Print commands and their arguments as they are executed.

Examples

Start of a Bash script
#!/bin/bash -
Start of a Bash script in an unofficial 'Strict Mode'
#!/bin/bash -
set -o 'errexit' -o 'noglob' -o 'nounset' -o 'pipefail'
IFS=$'\t\n'
Show the value of some shell options
set -o | grep --regexp='^h'

Output:

hashall        	on
histexpand     	on
history        	on

References

  1. 1.0 1.1 bash -c 'help set'