CONTAINS(1) fish-shell CONTAINS(1)

# [NAME](#NAME)

contains - test if a word is present in a list

# [SYNOPSIS](#SYNOPSIS)

```
contains [OPTIONS] [--] KEY [VALUES ...]
```

# [DESCRIPTION](#DESCRIPTION)

**contains** tests whether the set *VALUES* contains the string *KEY*. If so, **contains** exits with code 0; if not, it exits with code 1.

The following options are available:

[**-i** or **--index**](#i)

Print the index (number of the element in the set) of the first matching element.

[**-h** or **--help**](#h)

Displays help about using this command.

Options must be passed before *KEY*. All arguments after *KEY* will be considered a value, regardless if they start with a **-** or not, including **--**. If *KEY* itself starts with a **-**, use a **--** argument to separate it from the options.

See the examples below.

# [EXAMPLE](#EXAMPLE)

If *animals* is a list of animals, the following will test if *animals* contains "cat":

```
if contains cat $animals


   echo Your animal list is evil!
end
```

This code will add some directories to **PATH** &lt;#envvar-PATH&gt; if they aren't yet included:

```
for i in ~/bin /usr/local/bin


    if not contains $i $PATH


        set PATH $PATH $i


    end
end
```

While this will check if function **hasargs** is being ran with the **-q** option:

```
function hasargs


    if contains -- -q $argv


        echo '$argv contains a -q option'


    end
end
```

The **--** here stops **contains** from treating **-q** to an option to itself. Instead it treats it as a normal string to check.

```
contains -i foo -q -- foo
```

This returns 3, since all arguments after the key are considered a value.

# [Copyright](#Copyright)

fish-shell developers

September 9, 2026 4.9

---

Document: contains(1) from fish 4.9.3-r0 (Chainguard OS)
Source: https://github.com/fish-shell/fish-shell
