.\" Man page generated from reStructuredText .\" by the Docutils 0.23 manpage writer. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "CONTAINS" "1" "Sep 09, 2026" "4.9" "fish-shell" .SH NAME contains \- test if a word is present in a list .SH SYNOPSIS .nf \fBcontains\fP [\fIOPTIONS\fP] [\fB\-\-\fP] \fIKEY\fP [\fIVALUES\fP \&...] .fi .sp .SH DESCRIPTION .sp \fBcontains\fP tests whether the set \fIVALUES\fP contains the string \fIKEY\fP\&. If so, \fBcontains\fP exits with code 0; if not, it exits with code 1. .sp The following options are available: .INDENT 0.0 .TP \fB\-i\fP or \fB\-\-index\fP Print the index (number of the element in the set) of the first matching element. .TP \fB\-h\fP or \fB\-\-help\fP Displays help about using this command. .UNINDENT .sp Options must be passed before \fIKEY\fP\&. All arguments after \fIKEY\fP will be considered a value, regardless if they start with a \fB\-\fP or not, including \fB\-\-\fP\&. If \fIKEY\fP itself starts with a \fB\-\fP, use a \fB\-\-\fP argument to separate it from the options. .sp See the examples below. .SH EXAMPLE .sp If \fIanimals\fP is a list of animals, the following will test if \fIanimals\fP contains \(dqcat\(dq: .INDENT 0.0 .INDENT 3.5 .sp .EX if contains cat $animals echo Your animal list is evil! end .EE .UNINDENT .UNINDENT .sp This code will add some directories to \fBPATH\fP \%<#\:envvar-PATH> if they aren\(aqt yet included: .INDENT 0.0 .INDENT 3.5 .sp .EX for i in ~/bin /usr/local/bin if not contains $i $PATH set PATH $PATH $i end end .EE .UNINDENT .UNINDENT .sp While this will check if function \fBhasargs\fP is being ran with the \fB\-q\fP option: .INDENT 0.0 .INDENT 3.5 .sp .EX function hasargs if contains \-\- \-q $argv echo \(aq$argv contains a \-q option\(aq end end .EE .UNINDENT .UNINDENT .sp The \fB\-\-\fP here stops \fBcontains\fP from treating \fB\-q\fP to an option to itself. Instead it treats it as a normal string to check. .INDENT 0.0 .INDENT 3.5 .sp .EX contains \-i foo \-q \-\- foo .EE .UNINDENT .UNINDENT .sp This returns 3, since all arguments after the key are considered a value. .SH Copyright fish-shell developers .\" End of generated man page.