documentation for test and function (closes: #734)

plus speling in documentation for bind.
Note that this commit does not re-enable the generation of the manpage for
test, which will therefore still fall through to the system manual page with
`man test`.
This commit is contained in:
David Adam (zanchey) 2013-07-29 16:06:05 +08:00
parent be77b9201e
commit 27d84ef8be
3 changed files with 81 additions and 24 deletions

View file

@ -48,7 +48,7 @@ readable as well.
Key bindings are not saved between sessions by default. To save custom Key bindings are not saved between sessions by default. To save custom
keybindings, edit the \c fish_user_key_bindings function and insert the keybindings, edit the \c fish_user_key_bindings function and insert the
appropirate \c bind statements. appropriate \c bind statements.
The following parameters are available: The following parameters are available:

View file

@ -12,16 +12,19 @@ function is given as a command.
The following options are available: The following options are available:
- <code>-a NAMES</code> or <code>--argument-names NAMES</code> assigns the value of successive command-line arguments to the names given in NAMES.
- <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description. - <code>-d DESCRIPTION</code> or \c --description=DESCRIPTION is a description of what the function does, suitable as a completion description.
- <code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt. - <code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt.
- <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group ID PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution. - <code>-j PID</code> or <code> --on-job-exit PID</code> tells fish to run this function when the job with group ID PID exits. Instead of PID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.
- <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process ID PID exits. - <code>-p PID</code> or <code> --on-process-exit PID</code> tells fish to run this function when the fish child process with process ID PID exits.
- <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP). - <code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP).
- \c -S or \c --no-scope-shadowing allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function.
- <code>-v</code> or <code>--on-variable VARIABLE_NAME</code> tells fish to run this function when the variable VARIABLE_NAME changes value. - <code>-v</code> or <code>--on-variable VARIABLE_NAME</code> tells fish to run this function when the variable VARIABLE_NAME changes value.
If the user enters any additional arguments after the function, they If the user enters any additional arguments after the function, they
are inserted into the environment <a href="index.html#variables-arrays">variable array</a> are inserted into the environment <a href="index.html#variables-arrays">variable array</a>
<code>$argv</code>. <code>$argv</code>. If the \c --argument-names option is provided, the arguments are
also assigned to names specified in that option.
By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href="#emit">emit</a> builtin. Fish generates the following named events: By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href="#emit">emit</a> builtin. Fish generates the following named events:

View file

@ -6,37 +6,91 @@
\subsection test-description Description \subsection test-description Description
Tests the expression given and sets the exit status to 0 if true, Tests the expression given and sets the exit status to 0 if true,
and 1 if false. and 1 if false. An expression is made up of one or more operators
and their arguments.
The following options are available: The following operators are available to examine files and directories:
- \c -h displays a help message and then exits.
- <tt>-L FILE</tt> returns true if \c FILE is a symbolic link.
- <tt>-S FILE</tt> returns true if \c FILE is a socket.
- <tt>COND1 -a COND2</tt> combines two conditions with a logical and.
- <tt>-b FILE</tt> returns true if \c FILE is a block device. - <tt>-b FILE</tt> returns true if \c FILE is a block device.
- <tt>-c FILE</tt> returns true if \c FILE is a character device. - <tt>-c FILE</tt> returns true if \c FILE is a character device.
- <tt>-d FILE</tt> returns true if \c FILE is a directory. - <tt>-d FILE</tt> returns true if \c FILE is a directory.
- <tt>-e FILE</tt> returns true if \c FILE exists. - <tt>-e FILE</tt> returns true if \c FILE exists.
- <tt>-f FILE</tt> returns true if \c FILE is a regular file. - <tt>-f FILE</tt> returns true if \c FILE is a regular file.
- <tt>-f FILE</tt> returns true if \c FILE has set-group-ID bit set. - <tt>-g FILE</tt> returns true if \c FILE has the set-group-ID bit set.
- <tt>-n STRING</tt> returns true if the length of \c STRING is non-zero. - <tt>-L FILE</tt> returns true if \c FILE is a symbolic link.
- <tt>COND1 -o COND2</tt> combines two conditions with a logical or.
- <tt>-p FILE</tt> returns true if \c FILE is a named pipe. - <tt>-p FILE</tt> returns true if \c FILE is a named pipe.
- <tt>-r FILE</tt> returns true if \c FILE is readable. - <tt>-r FILE</tt> returns true if \c FILE is marked as readable.
- <tt>-s FILE</tt> returns true if the size of \c FILE is non-zero. - <tt>-s FILE</tt> returns true if the size of \c FILE is greater than zero.
- <tt>-t FD</tt> returns true if \c FD is a terminal (TTY). - <tt>-S FILE</tt> returns true if \c FILE is a socket.
- <tt>-u FILE</tt> returns true if \c FILE has set-user-ID bit set. - <tt>-t FD</tt> returns true if the file descriptor \c FD is a terminal (TTY).
- <tt>-w FILE</tt> returns true if \c FILE is writable. - <tt>-u FILE</tt> returns true if \c FILE has the set-user-ID bit set.
- <tt>-x FILE</tt> returns true if \c FILE is executable. - <tt>-w FILE</tt> returns true if \c FILE is marked as writable; note that this does not check if the filesystem is read-only.
- <tt>-z STRING</tt> returns true if \c STRING length is zero. - <tt>-x FILE</tt> returns true if \c FILE is marked as executable.
\subsection test-example Example The following operators are available to compare and examine text strings:
- <tt>STRING1 = STRING2</tt> returns true if the strings \c STRING1 and
\c STRING2 are identical.
- <tt>STRING1 != STRING2</tt> returns true if the strings \c STRING1 and
\c STRING2 are not identical.
- <tt>-n STRING</tt> returns true if the length of \c STRING is non-zero.
- <tt>-z STRING</tt> returns true if the length of \c STRING is zero.
The following operators are available to compare and examine numbers:
- <tt>NUM1 -eq NUM2</tt> returns true if \c NUM1 and \c NUM2 are numerically equal.
- <tt>NUM1 -ne NUM2</tt> returns true if \c NUM1 and \c NUM2 are not numerically equal.
- <tt>NUM1 -gt NUM2</tt> returns true if \c NUM1 is greater than <tt>NUM2</tt>.
- <tt>NUM1 -ge NUM2</tt> returns true if \c NUM1 is greater than or equal to <tt>NUM2</tt>.
- <tt>NUM1 -lt NUM2</tt> returns true if \c NUM1 is less than <tt>NUM2</tt>.
- <tt>NUM1 -le NUM2</tt> returns true if \c NUM1 is less than or equal to <tt>NUM2</tt>.
Note that only integers are supported. For more complex mathematical
operations, including fractions, the \c env program may be useful. Consult the
documentation for your operating system.
Expressions can be combined using the following operators:
- <tt>COND1 -a COND2</tt> returns true if both \c COND1 and \c COND2 are true.
- <tt>COND1 -o COND2</tt> returns true if either \c COND1 or \c COND2 are true.
Expressions can be inverted using the \c ! operator:
- <tt>! EXPRESSION</tt> returns true if \c EXPRESSION is false, and false if
\c EXPRESSION is true.
Expressions can be grouped using parentheses.
- <tt>( EXPRESSION )</tt> returns the value of <tt>EXPRESSION</tt>.
Note that parentheses will usually require escaping with <tt>\\(</tt> to avoid
being interpreted as a command substitution.
\subsection test-example Examples
If the \c /tmp directory exists, copy the \c /etc/motd file to it:
<pre> <pre>
if test -d "/" if test -d /tmp
echo "Fish is cool" cp /etc/motd /tmp/motd
end end
</pre> </pre>
If the variable \c MANPATH is defined and not empty, print the contents:
<pre>
if test -n $MANPATH
echo $MANPATH
end
</pre>
Parentheses and the \c -o and \c -a operators can be combined to produce
more complicated expressions. In this example, success is printed if there is
a \c /foo or \c /bar file as well as a \c /baz or \c /bat file.
<pre>
if test \\( -f /foo -o -f /bar \\) -a \\( -f /baz -o -f /bat \\)
echo Success.
end.
</pre>
\subsection test-standards Standards
\c test implements a subset of the
<a href="http://www.unix.com/man-page/POSIX/1/test/">IEEE Std 1003.1-2008
(POSIX.1) standard</a>. The following exceptions apply:
- The \c < and \c > operators for comparing strings are not implemented.
Because "/" is a directory, the expression will evaluate to true, and
"Fish is cool" will be output.