2006-10-31 15:23:16 +00:00
\section contains contains - test if a word is present in a list
2006-01-26 17:34:37 +00:00
\subsection contains-synopsis Synopsis
2014-08-01 12:25:41 +00:00
\fish{synopsis}
2014-08-01 02:37:32 +00:00
contains [OPTIONS] KEY [VALUES...]
\endfish
2006-01-26 17:34:37 +00:00
\subsection contains-description Description
2014-08-19 12:41:23 +00: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-26 17:34:37 +00: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 07:56:01 +00:00
The following options are available:
2006-01-26 17:34:37 +00:00
2014-08-01 02:37:32 +00:00
- `-i` or `--index` print the word index
2006-01-26 17:34:37 +00:00
2018-05-13 22:36:49 +00: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 12:41:23 +00:00
2006-01-26 17:34:37 +00:00
\subsection contains-example Example
2014-08-01 02:37:32 +00:00
2018-05-13 22:36:49 +00: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 02:37:32 +00:00
\fish
2006-01-26 17:34:37 +00:00
for i in ~/bin /usr/local/bin
2014-08-01 02:37:32 +00:00
if not contains $i $PATH
set PATH $PATH $i
end
2006-01-26 17:34:37 +00:00
end
2014-08-01 02:37:32 +00:00
\endfish
2006-01-26 17:34:37 +00:00
2018-05-13 22:36:49 +00:00
While this will check if `hasargs` was run with the `-q` option:
2014-10-26 11:01:22 +00:00
\fish
function hasargs
if contains -- -q $argv
echo '$argv contains a -q option'
end
end
\endfish
2018-05-13 22:36:49 +00:00
The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check.