diff options
Diffstat (limited to 'doc_src/contains.txt')
-rw-r--r-- | doc_src/contains.txt | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/doc_src/contains.txt b/doc_src/contains.txt index cc746358..3b5060ba 100644 --- a/doc_src/contains.txt +++ b/doc_src/contains.txt @@ -1,26 +1,38 @@ \section contains contains - test if a word is present in a list \subsection contains-synopsis Synopsis -<code>contains [OPTIONS] KEY [VALUES...]</code> +\fish{synopsis} +contains [OPTIONS] KEY [VALUES...] +\endfish \subsection contains-description Description -\c contains tests whether the set \c VALUES contains the string -<code>KEY</code>. If so, \c contains exits with status 0; if not, it exits -with status 1. +`contains` tests whether the set `VALUES` contains the string `KEY`. If so, `contains` exits with status 0; if not, it exits with status 1. The following options are available: -- \c -i or \c --index print the word index -- \c -h or \c --help display this message +- `-i` or `--index` print the word index + +Note that, like GNU tools, `contains` interprets all arguments starting with a `-` as options to contains, until it reaches an argument that is `--` (two dashes). See the examples below. \subsection contains-example Example -<pre> + +\fish for i in ~/bin /usr/local/bin - if not contains \$i \$PATH - set PATH \$PATH \$i - end + if not contains $i $PATH + set PATH $PATH $i + end +end +\endfish + +The above code tests if `~/bin` and `/usr/local/bin` are in the path and adds them if not. + +\fish +function hasargs + if contains -- -q $argv + echo '$argv contains a -q option' + end end -</pre> +\endfish -The above code tests if \c ~/bin and \c /usr/local/bin are in the path and adds them if not. +The above code checks for `-q` in the argument list, using the `--` argument to demarcate options to `contains` from the key to search for. |