aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc_src/count.txt
blob: 7287e19b61c288b9f06c78081d1eb1d96efe2dfe (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
\section count count - count the number of elements of an array

\subsection count-synopsis Synopsis
 <tt>count $VARIABLE</tt>

\subsection count-description Description

The <tt>count</tt> builtin prints the number of arguments that were
passed to it. This is usually used to find out how many elements an
environment variable array contains, but this is not the only
potential usage for the count command.

The count command does not accept any options, not even '-h'. This way
the user does not have to worry about an array containing elements
such as dashes. \c fish performs a special check when invoking the
count command, and if the user uses a help option, this help page is
displayed, but if a help option is contained inside of a variable or
is the result of expansion, it will simply be counted like any other
argument.

Count exits with a non-zero exit status if no arguments where passed
to it, with zero otherwise.

\subsection count-example Example

<pre>
count $PATH
</pre>

returns the number of directories in the users PATH variable.

<pre>
count *.txt
</pre>

returns the number of files in the current working directory ending with the suffix '.txt'.