mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 19:53:36 +08:00
e7a964fdfa
As a simple replacement for `wc -l`. This counts both lines on stdin _and_ arguments. So if "file" has three lines, then `count a b c < file` will print 6. And since it counts newlines, like wc, `echo -n foo | count` prints 0.
39 lines
617 B
Fish
39 lines
617 B
Fish
# Validate the behavior of the `count` command.
|
|
|
|
logmsg no args
|
|
count
|
|
|
|
logmsg one args
|
|
count x
|
|
|
|
logmsg two args
|
|
count x y
|
|
|
|
logmsg args that look like flags or are otherwise special
|
|
count -h
|
|
count --help
|
|
count --
|
|
count -- abc
|
|
count def -- abc
|
|
|
|
logmsg big counts
|
|
|
|
# See #5611
|
|
for i in seq 500
|
|
set c1 (count (seq 1 10000))
|
|
test $c1 -eq 10000
|
|
or begin
|
|
echo "Count $c1 is not 10000"
|
|
break
|
|
end
|
|
end
|
|
|
|
logmsg stdin
|
|
# Reading from stdin still counts the arguments
|
|
printf '%s\n' 1 2 3 4 5 | count 6 7 8 9 10
|
|
|
|
# Reading from stdin counts newlines - like `wc -l`.
|
|
echo -n 0 | count
|
|
|
|
echo 1 | count
|