#!/bin/bash
# /usr/local/bin/wc
# http://crystalfaeries.net/posix/bin/wc
# celeste:crystalfaery 2016-08-04 20:57:37+00:00
# This is a simple shell-script wrapper for the POSIX system command "wc" to add some functionality:
# Presumably the POSIX $PATH variable places us (default: /usr/local/bin) ahead of usual system commands.
# CONFIGURATION:
wc=/usr/bin/wc # the real wc, which presumably we have taken-over-for by being earlier in search path
# COMMAND-LINE ARGUMENTS:
while [[ $# -ne 0 ]]
do
case "$1" in
"--help")
echo "Usage: $0 [-W]|[--help]|[$wc <options>]"
echo "-W word count each word individually"
echo -n "--help displays $0 help; <ENTER> to invoke '$wc --help':"
read answer
exec $wc "$@" | less
exit $?
;;
-W)
shift # Yes, I know I'm not handling standard input yet!
cp /dev/null /tmp/wc.$$.txt
while [[ $# -ne 0 ]]
do
cat "$1" >> /tmp/wc.$$.txt
# echo "$($wc -w $1)" # action of "-w"
shift
done
# echo "Total Word Counts:"
tr '[:upper:]' '[:lower:]' < /tmp/wc.$$.txt | tr -cs '[:alpha:]' '\n' | sort | uniq -c | sort -nr
rm /tmp/wc.$$.txt
exit $?
;;
*)
exec $wc "$@" # pass all arguments through
exit $?
;;
esac
shift
done
exec $wc "$@" # pass all arguments through
let result=$?
if [[ $result -ne 0 ]]
then
echo "$0 exit: $result"
fi
exit $result
syntax highlighted by Code2HTML, v. 0.9.1