diff options
author | hubertf <hubertf@NetBSD.org> | 2007-01-24 13:17:42 +0000 |
---|---|---|
committer | hubertf <hubertf@NetBSD.org> | 2007-01-24 13:17:42 +0000 |
commit | 0bfeb2bae7cdd0f155a91d2d08ff860792812532 (patch) | |
tree | b3296ef46b323be64e7610bfc2e3a2c96f9e6cc5 /wtf | |
parent | ec757acff77108e4e82f339f042fc100841d4945 (diff) | |
download | bsdgames-darwin-0bfeb2bae7cdd0f155a91d2d08ff860792812532.tar.gz bsdgames-darwin-0bfeb2bae7cdd0f155a91d2d08ff860792812532.tar.zst bsdgames-darwin-0bfeb2bae7cdd0f155a91d2d08ff860792812532.zip |
- Don't call basename $0 at many places. Use variable $PROGNAME
- Better check when neither $ACRONYMDB is define nor files in
/usr/share/misc/ are found
- Replace cat | fgrep to using fgrep only
- Replace sort | uniq to using sort -u
By Slava Semushin <slava.semushin@gmail.com> in private email.
Diffstat (limited to 'wtf')
-rw-r--r-- | wtf/wtf | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -1,16 +1,23 @@ #!/bin/sh # -# $NetBSD: wtf,v 1.13 2005/07/01 14:21:49 peter Exp $ +# $NetBSD: wtf,v 1.14 2007/01/24 13:17:42 hubertf Exp $ # # Public domain # +PROGNAME=`basename $0` + usage() { - echo "usage: `basename $0` [-f dbfile] [is] <acronym>" + echo "usage: $PROGNAME [-f dbfile] [is] <acronym>" exit 1 } -acronyms=${ACRONYMDB:-`ls /usr/share/misc/acronyms*`} +acronyms=${ACRONYMDB:-`ls /usr/share/misc/acronyms* 2>/dev/null`} + +if [ "$acronyms" = "" ]; then + echo "$PROGNAME: acronyms database not found!" >&2 + exit 1 +fi args=`getopt f: $*` if [ $? -ne 0 ]; then @@ -40,7 +47,7 @@ fi for f in $acronyms do if [ ! -f $f ]; then - echo "`basename $0`: cannot open acronyms database file \`$f'" 1>&2 + echo "$PROGNAME: cannot open acronyms database file \`$f'" >&2 exit 1 fi done @@ -49,7 +56,7 @@ rv=0 while [ $# -gt 0 ] ; do # Search acronyms list first target=`echo $1 | tr '[a-z]' '[A-Z]'` - ans=`cat $acronyms | fgrep -h $target 2>/dev/null \ + ans=`fgrep -h $target $acronyms 2>/dev/null \ | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"` if [ "$ans" != "" ] ; then echo "$target: $ans" @@ -59,7 +66,7 @@ while [ $# -gt 0 ] ; do # Try whatis(1) next ans=`whatis $1 2>/dev/null` if [ $? -eq 0 ] ; then - echo "$ans" | sort | uniq + echo "$ans" | sort -u shift ; continue fi @@ -71,7 +78,7 @@ while [ $# -gt 0 ] ; do fi # Give up! - echo "`basename $0`, I don't know what $1 means!" 1>&2 + echo "$PROGNAME: I don't know what $1 means!" 1>&2 rv=1 shift |