diff options
Diffstat (limited to 'os1w5/lettercount.sh')
-rwxr-xr-x | os1w5/lettercount.sh | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/os1w5/lettercount.sh b/os1w5/lettercount.sh new file mode 100755 index 0000000..9ff3436 --- /dev/null +++ b/os1w5/lettercount.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +usage() { + echo "usage: $0 <file> <letter1> [letter2] [letter3] [...]" + exit 1 +} + +[[ ! -f "$1" ]] && echo "file does not exist" && usage +[[ "$#" -lt 2 ]] && echo "not enough arguments" && usage + +file="$1" +shift +for letter in "$@"; do + [[ ! "${#letter}" -eq 1 ]] && echo "argument \"$letter\" too long" && usage + echo "$letter -> `cat $file | tr -cd $letter | wc -c`" +done + |