2006-10-31 23:23:16 +08:00
\section contains contains - test if a word is present in a list
2006-01-27 01:34:37 +08:00
\subsection contains-synopsis Synopsis
2014-08-01 20:25:41 +08:00
\fish{synopsis}
2014-08-01 10:37:32 +08:00
contains [OPTIONS] KEY [VALUES...]
\endfish
2006-01-27 01:34:37 +08:00
\subsection contains-description Description
2014-08-19 20:41:23 +08:00
`contains` tests whether the set `VALUES` contains the string `KEY`. If so, `contains` exits with status 0; if not, it exits with status 1.
2006-01-27 01:34:37 +08: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 15:56:01 +08:00
The following options are available:
2006-01-27 01:34:37 +08:00
2014-08-01 10:37:32 +08:00
- `-i` or `--index` print the word index
2006-01-27 01:34:37 +08:00
2014-10-26 19:01:22 +08:00
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.
2014-08-19 20:41:23 +08:00
2006-01-27 01:34:37 +08:00
\subsection contains-example Example
2014-08-01 10:37:32 +08:00
\fish
2006-01-27 01:34:37 +08:00
for i in ~/bin /usr/local/bin
2014-08-01 10:37:32 +08:00
if not contains $i $PATH
set PATH $PATH $i
end
2006-01-27 01:34:37 +08:00
end
2014-08-01 10:37:32 +08:00
\endfish
2006-01-27 01:34:37 +08:00
2014-08-01 10:37:32 +08:00
The above code tests if `~/bin` and `/usr/local/bin` are in the path and adds them if not.
2014-10-26 19:01:22 +08:00
\fish
function hasargs
if contains -- -q $argv
echo '$argv contains a -q option'
end
end
\endfish
The above code checks for `-q` in the argument list, using the `--` argument to demarcate options to `contains` from the key to search for.