Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [203]

By Root 864 0
for set

The set command in both shells accepts additional short and long options. The full set of set options, for both shells, is given in Table 14-2. Items marked POSIX are available in both bash and the Korn shell.

Table 14-2. Shell options for set

Short option

-o form

Availability

Description

-a

allexport

POSIX

Export all subsequently defined variables.

-A

ksh88, ksh93

Array assignment. set +A does not clear the array. See Section 14.3.6 for more information.

-b

notify

POSIX

Print job completion messages right away, instead of waiting for next prompt. Intended for interactive use.

-B

braceexpand

bash

Enable brace expansion. On by default. See Section 14.3.4 for more information.

-C

noclobber

POSIX

Don't allow > redirection to existing files. The >| operator overrides the setting of this option. Intended for interactive use.

-e

errexit

POSIX

Exit the shell when a command exits with nonzero status.

-f

noglob

POSIX

Disable wildcard expansion.

-h

hashall (bash)

POSIX

Locate and remember the location of commands called from function bodies when the function is defined, instead of when the function is executed (XSI).

trackall (ksh)

-H

histexpand

bash

Enable !-style history expansion. On by default.[1]

-k

keyword

bash,ksh88, ksh93

Put all variable assignments into the environment, even those in the middle of a command. This is an obsolete feature and should never be used.

-m

monitor

POSIX

Enable job control (on by default). Intended for interactive use.

-n

noexec

POSIX

Read commands and check for syntax errors, but don't execute them. Interactive shells are allowed to ignore this option.

-p

privileged

bash,ksh88, ksh93

Attempt to function in a more secure mode. The details differ among the shells; see your shell's documentation.

-P

physical

bash

Use the physical directory structure for commands that change directory.

-s

ksh88, ksh93

Sort the positional parameters.

-t

bash,ksh88, ksh93

Read and execute one command and then exit. This is obsolete; it is for compatibility with the Bourne shell and should not be used.

-u

nounset

POSIX

Treat undefined variables as errors, not as null.

-v

verbose

POSIX

Print commands (verbatim) before running them.

-x

xtrace

POSIX

Print commands (after expansions) before running them.

bgnice

ksh88, ksh93

Automatically lower the priority of all commands run in the background (with &).

emacs

bash,ksh88, ksh93

Use emacs-style command-line editing. Intended for interactive use.

gmacs

ksh88, ksh93

Use GNU emacs-style command-line editing. Intended for interactive use.

history

bash

Enable command history. On by default.

ignoreeof

POSIX

Disallow Ctrl-D to exit the shell.

markdirs

ksh88, ksh93

Append a / to directories when doing wildcard expansion.

nolog

POSIX

Disable command history for function definitions.

pipefail

ksh93

Make pipeline exit status be that of the last command that fails, or zero if all OK. ksh93n or newer.

posix

bash

Enable full POSIX compliance.

vi

POSIX

Use vi-style command-line editing. Intended for interactive use.

viraw

ksh88, ksh93

Use vi-style command-line editing. Intended for interactive use. This mode can be slightly more CPU-intensive than set -o vi.

[1] We recommend disabling this feature if you use bash.

The bash shopt Command

The bash shell, besides using the set command with long and short options, has a separate shopt command for enabling and disabling options.

* * *

shopt (bash)


Usage

shopt [ -pqsu ] [ -o ] [ option-name ... ]

Purpose

To centralize control of shell options as they're added to bash, instead of proliferating set options or shell variables.

Major options

-o

Limit options to those that can be set with set -o.

-p

Print output

Return Main Page Previous Page Next Page

®Online Book Reader