[count] Allow counting lines from stdin

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.
This commit is contained in:
Fabian Homborg
2018-01-04 00:42:12 +01:00
parent cb36a9ca36
commit e7a964fdfa
5 changed files with 55 additions and 4 deletions

View File

@@ -13,3 +13,6 @@
####################
# big counts
####################
# stdin

View File

@@ -27,3 +27,12 @@ for i in seq 500
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

View File

@@ -21,3 +21,9 @@
####################
# big counts
####################
# stdin
10
0
1