2014-04-19 00:16:37 +00:00
\section set set - display and change shell variables.
2005-09-20 13:31:55 +00:00
\subsection set-synopsis Synopsis
2006-09-19 14:52:03 +00:00
<pre>
set [SCOPE_OPTIONS]
2006-06-04 20:14:51 +00:00
set [OPTIONS] VARIABLE_NAME VALUES...
set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES...
set (-q | --query) [SCOPE_OPTIONS] VARIABLE_NAMES...
set (-e | --erase) [SCOPE_OPTIONS] VARIABLE_NAME
2006-09-19 14:52:03 +00:00
set (-e | --erase) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]...
</pre>
2006-05-27 13:47:23 +00:00
2005-09-20 13:31:55 +00:00
\subsection set-description Description
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
2014-04-19 00:16:37 +00:00
<code>set</code> manipulates <a href="index.html#variables">shell
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
variables</a>.
If set is called with no arguments, the names and values of all
2014-04-19 00:16:37 +00:00
shell variables are printed. If some of the scope or export
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
flags have been given, only the variables matching the specified scope
are printed.
With both variable names and values provided, \c set assigns the variable
<code>VARIABLE_NAME</code> the values <code>VALUES...</code>.
The following options control variable scope:
2014-04-19 00:16:37 +00:00
- <code>-l</code> or <code>--local</code> forces the specified shell variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local
- <code>-g</code> or <code>--global</code> causes the specified shell variable to be given a global scope. Non-global variables disappear when the block they belong to ends
- <code>-U</code> or <code>--universal</code> causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.
- <code>-x</code> or <code>--export</code> causes the specified shell variable to be exported to child processes (making it an "environment variable")
- <code>-u</code> or <code>--unexport</code> causes the specified shell variable to NOT be exported to child processes
2005-09-20 13:31:55 +00:00
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
The following options are available:
2014-04-19 00:16:37 +00:00
- <code>-e</code> or <code>--erase</code> causes the specified shell variable to be erased
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
- <code>-q</code> or <code>--query</code> test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined.
2014-07-12 07:21:04 +00:00
- <code>-n</code> or <code>--names</code> List only the names of all defined variables, not their value
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
- <code>-L</code> or <code>--long</code> do not abbreviate long values when printing set variables
2005-09-20 13:31:55 +00:00
If a variable is set to more than one value, the variable will be an
2005-12-07 16:29:24 +00:00
array with the specified elements. If a variable is set to zero
elements, it will become an array with zero elements.
2005-09-20 13:31:55 +00:00
2006-01-28 02:19:33 +00:00
If the variable name is one or more array elements, such as
<code>PATH[1 3 7]</code>, only those array elements specified will be
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
changed. When array indices are specified to \c set, multiple arguments
2006-05-27 13:47:23 +00:00
may be used to specify additional indexes, e.g. <code>set PATH[1]
2006-06-04 09:42:03 +00:00
PATH[4] /bin /sbin</code>. If you specify a negative index when
expanding or assigning to an array variable, the index will be
calculated from the end of the array. For example, the index -1 means
the last index of an array.
2006-06-08 23:58:11 +00:00
The scoping rules when creating or updating a variable are:
2006-06-03 23:15:17 +00:00
-# If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed.
2007-08-01 17:35:24 +00:00
-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previous variable scope is used.
2012-12-29 15:39:41 +00:00
-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the \c -l or \c --local flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global.
2006-06-03 23:15:17 +00:00
2006-06-08 23:58:11 +00:00
The exporting rules when creating or updating a variable are identical
to the scoping rules for variables:
2006-06-03 23:15:17 +00:00
-# If a variable is explicitly set to either be exported or not exported, that setting will be honored.
-# If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.
2008-01-08 21:36:00 +00:00
-# If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported.
2006-06-03 23:15:17 +00:00
2006-06-04 20:14:51 +00:00
In query mode, the scope to be examined can be specified.
In erase mode, if variable indices are specified, only the specified
2014-07-12 21:40:46 +00:00
slices of the array variable will be erased.
2006-06-03 23:15:17 +00:00
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
\c set requires all options to come before any
other arguments. For example, <code>set flags -l</code> will have
2006-01-28 02:19:33 +00:00
the effect of setting the value of the variable <code>flags</code> to
'-l', not making the variable local.
2005-09-20 13:31:55 +00:00
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
In assignment mode, \c set exits with a non-zero exit status if variable
2013-01-31 23:57:08 +00:00
assignments could not be successfully performed. If the variable assignments
were performed, the exit status is unchanged. This allows simultaneous capture
of the output and exit status of a subcommand, e.g. <code>if set output
(command)</code>. In query mode, the exit status is the number of variables that
Help cleanup
Large list of changes, including formatting and typos for most commands.
More substantive changes have been made to alias, bind, block, break,
builtin, case, cd, commandline, count, else, emit, fish_config, funced,
function, functions, history, math, mimedb, nextd, not, popd, prevd,
pushd, pwd, random, read, set, set_color, switch, test, trap, type,
ulimit, umask, and while.
2013-05-12 07:56:01 +00:00
were not found. In erase mode, \c set exits with a zero exit status in case of
2013-01-31 23:57:08 +00:00
success, with a non-zero exit status if the commandline was invalid, if the
variable was write-protected or if the variable did not exist.
2006-06-03 23:15:17 +00:00
2005-09-20 13:31:55 +00:00
\subsection set-example Example
2006-01-11 13:29:44 +00:00
<code>set -xg</code> will print all global, exported variables.
2005-09-20 13:31:55 +00:00
2006-01-11 13:29:44 +00:00
<code>set foo hi</code> sets the value of the variable foo to be hi.
2005-09-20 13:31:55 +00:00
2006-01-11 13:29:44 +00:00
<code>set -e smurf</code> removes the variable \c smurf.
<code>set PATH[4] ~/bin</code> changes the fourth element of the \c PATH array to \c ~/bin
2013-01-31 23:57:08 +00:00
<pre>if set python_path (which python)
echo "Python is at $python_path"
end</pre>
The above outputs the path to Python if \c which returns true.