set

NAME

set - shell built-in to set and clear shell options

SYNOPSIS

C shell

set [-r]			

Korn shell

set [+-abCefhkmnpsuvxX] [+-o [option]]
	[+-A name] [--] [arg ...]

DESCRIPTION

C shell

The set(1) command displays the value of all shell variables. You can also use set(1) to assign the value of a variable to a null string, a word, or multiple words (a word list).

You can repeat these arguments in a single set(1) command to set multiple variables, make multiple variables read only, or do both. Note, however, that variable expansion happens for all arguments before any setting occurs. Note also that "=" can be adjacent to both the variable name and the word, or separated from both by white space. It cannot, however, be adjacent to only one or the other. See also the unset(1) built-in command.

-r
Sets a variable to read only.

Korn shell

The set(1) command can be used to set (-) or clear (+) shell options, set the positional parameters, or set an array parameter. Options can be changed using the +-o option syntax, where option is the long name of an option, or using the +-letter syntax, where letter is the option's single letter name (not all options have a single letter name).

The following list provides option letters (if they exist) and long names, along with a description of what the option does.

-A name arg ...
Sets the elements of the array parameter name to arg.... If -A is used, the array is reset (that is, emptied) first; if +A is used, the first N elements are set (where N is the number of args), the remainder are left untouched.
-a (allexport)
All new parameters are created with the export attribute.
-b (notify)
Print job notification messages asynchronously, instead of just before the prompt. Only used if job control is enabled (-m).
-C (noclobber)
Prevent > redirection from overwriting existing files (>| must be used to force an overwrite).
-e (errexit)
Exit (after executing the ERR trap) as soon as an error occurs or a command fails (that is, it exits with a non-zero status). This does not apply to commands whose exit status is explicitly tested by a shell construct, such as if(1), until(1), while(1), &&, or || statements.
-f (noglob)
Do not expand file-name patterns.
-h (trackall)
Create tracked aliases for all executed commands. On by default for non-interactive shells.
-i (interactive)
Enable interactive mode; this can only be set/unset when the shell is invoked.
-k (keyword)
Parameter assignments are recognized anywhere in a command.
-l (login)
The shell is a login shell. This can only be set/unset when the shell is invoked.
-m (monitor)
Enable job control (default for interactive shells).
-n (noexec)
Do not execute any commands. Useful for checking the syntax of scripts (ignored if interactive).
-p (privileged)
Set automatically if, when the shell starts, the read user identifier (UID) or group identifier (GID) does not match the effective UID or GID, respectively.
-r (restricted)
Enable restricted mode. This option can only be used when the shell is invoked.
-s (stdin)
If used when the shell is invoked, commands are read from standard input. Set automatically if the shell is invoked with no arguments.

When -s is used in the set(1) command, it causes the specified arguments to be sorted before assigning them to the positional parameters (or to array name if -A is used).

-u (nounset)
Referencing of an unset parameter is treated as an error, unless one of the -, +, or = modifiers is used.
-v (verbose)
Write shell input to standard error as it is read.
-x (xtrace)
Print commands and parameter assignments when they are executed, preceded by the value of PS4.
-X (markdirs)
Mark directories with a trailing / during file-name generation.
bgnice
Background jobs are run with lower priority.
braceexpand
Enable brace expansion (also known as alternation).
cmd_intitle
Displays the current command line in the terminal window's title bar.
emacs
Enable BRL emacs-like command-line editing (interactive shells only).
gmacs
Enable gmacs-like (Gosling emacs) command-line editing (interactive shells only); currently identical to emacs editing except that transpose (^T) acts slightly differently.
ignoreeof
The shell will not exit when end-of-file is read, exit(1) must be used.
nohup
Do not kill running jobs with a HUP signal when a login shell exists. Currently set by default, but this will change in the future to be compatible with the original Korn shell (which does not have this option, but does send the HUP signal).
nolog
No effect in the original Korn shell; this prevents function definitions from being stored in the history file.
physical
Causes the cd(1) and pwd(1) commands to use 'physical' (that is, the file system's) .. directories instead of 'logical' directories (the shell handles .., which allows the user to remain unaware of symlink links to directories). Clear by default. Note that setting this option does not affect the current value of the PWD parameter; only the cd(1) command changes PWD. See the cd(1) and pwd(1) commands for more details.
posix
Enable posix mode.
vi
Enable vi-like command-line editing (interactive shells only).
viraw
No effect. In most implementations of the Korn shell, unless the viraw option was set, the vi command-line mode would let the tty driver do the work until ESC (^[) was entered. The Interix ksh(1) utility is always in viraw mode.
vi-esccomplete
In vi command-line editing, perform command completion and file-name completion when escape (^[) is entered in command mode.
vi-show8
Prefix characters with the eighth-bit set with M-. If this option is not set, characters in the range 128-160 are printed as is, which can cause problems.
vi-tabcomplete
In vi command-line editing, do command completion and file-name completion when tab (^I) is entered in insert mode.

These options can also be used upon invocation of the shell. The current set of options (with single-letter names) can be found in the parameter -. Using set -o with no option name will list all the options and whether each is on or off; set +o will print the long names of all options that are currently on.

Remaining arguments, if any, are positional parameters and are assigned, in order, to the positional parameters (that is, 1, 2, and so on). If options end with --, and there are no remaining arguments, all positional parameters are cleared. If no options or arguments are given, the values of all names are printed. For unknown historical reasons, a lone - option is treated specially: it clears both the -x and -v options.

DIAGNOSTICS

Korn shell

The set(1) utility exits with status 0 for success, and >0 if an error occurred.

EXAMPLES

C shell

set fname = Carl
Sets fname to Carl.
set buddy = "Rosana Campana"
Sets buddy to a string with a space.
set friends = (Tuttle Chen Solano)
Sets friends to word list.
set x=12 y=34 z=56
Sets x to 12, y to 34, and z to 56.

Korn shell

FNAME=Carl
Sets FNAME to Carl.
BUDDY="Rosana Campana"
Sets BUDDY to a string with a space.
set -x
Starts command tracing.
set +x
Stops command tracing. This is the default setting.
set -o noclobber
Prevents file overwriting.
set +o noclobber
Allows file overwriting. This is the default setting.