Make it possible to specify scope of a variable to be erased or tested. Also make sure set exits with a non-zero exit status when erasing fails.

darcs-hash:20060604201451-ac50b-4ea0212c513b33be40559dfe8d65c1446c53f682.gz
This commit is contained in:
axel
2006-06-05 06:14:51 +10:00
parent cf35a8e3a5
commit 04b142208d
8 changed files with 162 additions and 79 deletions

View File

@@ -1,11 +1,12 @@
\section set set - Handle environment variables.
\subsection set-synopsis Synopsis
<pre>set [OPTIONS] [VARIABLE_NAME [VALUES...]]
set [OPTIONS] [VARIABLE_NAME[INDICES]... [VALUES...]]
set -q VARIABLE_NAMES...
set (-e | --erase) VARIABLE_NAME[INDICES]...
set (-e | --erase) VARIABLE_NAME</pre>
<pre>set [SCOPE_OPTIONS]
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
set (-e | --erase) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]... </pre>
The <code>set</code> builtin causes fish to assign the variable <code>VARIABLE_NAME</code> the values <code>VALUES...</code>.
@@ -37,8 +38,6 @@ 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.
-# 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.
-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previos variable scope is used.
-# 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 functions. If no function is executing, the variable will be global.
@@ -47,20 +46,27 @@ the last index of an array.
-# 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.
-# If a variable is not explicitly set to be either global or local and has never before been defined, the variable will not be exported.
If the \c -e or \c --erase option is specified, the variable specified
by the following arguments will be erased. If variable indices are
specified, only the thecified slices of the array veraible will be
erased.
In query mode, the scope to be examined can be specified.
In erase mode, if variable indices are specified, only the specified
slices of the array variable will be erased. When erasing an entire
variable (i.e. no slicing), the scope of the variable to be erased can
be specified. That way, a global variable can be erased even if a
local variable with the same name exists. Scope can not be specified
when erasing a slice of an array. The innermost scope is always used.
The set command requires all switch arguments to come before any
non-switch arguments. For example, <code>set flags -l</code> will have
the effect of setting the value of the variable <code>flags</code> to
'-l', not making the variable local.
Set exits with an exit status of zero it the variable assignemnts
where sucessfully performed, with a non-zero exit status otherwise. In
query mode, the exit status is the number of variables that where not
found.
In assignment mode, set exits with an exit status of zero it the
variable assignments where sucessfully performed, with a non-zero exit
status otherwise. In query mode, the exit status is the number of
variables that where not found. In erase mode, set exits with a zero
exit status in case of success, with a non-zero exit status if the
commandline was invalid, if the variable was readprotected or if the
variable did not exist.
\subsection set-example Example