2006-10-31 15:23:16 +00:00
|
|
|
\section count count - count the number of elements of an array
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
\subsection count-synopsis Synopsis
|
|
|
|
<tt>count $VARIABLE</tt>
|
|
|
|
|
|
|
|
\subsection count-description Description
|
|
|
|
|
2007-07-31 21:23:32 +00:00
|
|
|
The <tt>count</tt> builtin prints the number of arguments that were
|
2007-04-23 22:00:26 +00:00
|
|
|
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.
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
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
|
2007-09-21 14:43:01 +00:00
|
|
|
count command, and if the user uses a help option, this help page is
|
2005-09-20 13:31:55 +00:00
|
|
|
displayed, but if a help option is contained inside of a variable or
|
2007-09-21 14:43:01 +00:00
|
|
|
is the result of expansion, it will simply be counted like any other
|
|
|
|
argument.
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2013-04-28 22:59:21 +00:00
|
|
|
Count exits with a non-zero exit status if no arguments were passed
|
|
|
|
to it, and with zero if at least one argument was passed.
|
2006-06-03 23:15:17 +00:00
|
|
|
|
2005-09-20 13:31:55 +00:00
|
|
|
\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'.
|