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
2018-05-14 06:36:49 +08:00
Note that, like GNU tools and most of fish's builtins, `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
2018-05-14 06:36:49 +08:00
If $animals is a list of animals, the following will test if it contains a cat:
\fish
if contains cat $animals
echo Your animal list is evil!
end
\endfish
This code will add some directories to $PATH if they aren't yet included:
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
2018-05-14 06:36:49 +08:00
While this will check if `hasargs` was run with the `-q` option:
2014-10-26 19:01:22 +08:00
\fish
function hasargs
if contains -- -q $argv
echo '$argv contains a -q option'
end
end
\endfish
2018-05-14 06:36:49 +08:00
The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check.