aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc_src/contains.txt
blob: 3b5060bad891707f867eb8d82dc6a14c680cdd2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
\section contains contains - test if a word is present in a list

\subsection contains-synopsis Synopsis
\fish{synopsis}
contains [OPTIONS] KEY [VALUES...]
\endfish

\subsection contains-description Description

`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:

- `-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

\fish
for i in ~/bin /usr/local/bin
    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
\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.