count - リストの要素数を数える

概要

count STRING1 STRING2 ...
COMMAND | count
count [...] < FILE

説明

count は、渡された引数の数に、標準入力(stdin)経由で渡された改行の数を加えて表示します。これは通常、環境変数リストに含まれる要素の数や、テキストファイルの行数を調べるために使用されます。

count はオプションを一切受け付けません。 -h--help も同様です。

count は、引数が一つも渡されなかった場合は非ゼロの終了ステータスで終了し、少なくとも一つの引数が渡された場合はゼロで終了します。

wc -l と同様に、標準入力からの読み込みでは「改行」の数を数えることに注意してください。そのため、 echo -n foo | count は 0 を表示します。

使用例

count $PATH
# Returns the number of directories in the users PATH variable.

count *.txt
# Returns the number of files in the current working directory
# ending with the suffix '.txt'.

git ls-files --others --exclude-standard | count
# Returns the number of untracked files in a git repository

printf '%s\n' foo bar | count baz
# Returns 3 (2 lines from stdin plus 1 argument)

count < /etc/hosts
# Counts the number of entries in the hosts file