shell script implementation of man
Matthew Hiles
matthew.hiles at gmail.com
Wed Nov 19 15:58:15 UTC 2008
I'll address all the replies at once.
> I assume that you did not see miscutils/man.c, i fear.
It appears man.c is for nroff files. This is a smaller, simpler
implementation meant to answer the request in the TODO. :D
> Did you test this with msh ?
The first version I posted, I did not. msh does not appear to support
$() style command substitution, it does support backticks. I've
changed the script and it appears to work with msh without any issues.
> Native French speaking: you could handle LANG and/or -L option (maybe
not) !
I will try, but later.
>This should default to /usr/share/man
Fixed.
So here's the updated version:
#!/bin/sh
# man - a simple man program for ASCII pages
# Copyright (c) 2008 Matthew Hiles
#
# Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
## requires: find, head, sort, tr, grep/egrep, and less
## optional: zcat, bzcat
#check to see if MANPATH is set and show warning if not
if [ -z "$MANPATH" ]; then
echo "Warning: MANPATH is not set, assuming /usr/share/man." >&2
MANPATH=/usr/share/man
fi
case $# in
1)
pagearg=$1 ;;
2)
section=man$1
pagearg=$2 ;;
*)
echo "Usage: man [section] <manpage>"
exit
esac
paths=`echo "$MANPATH" | tr ":" " "`
pagefile=`find $paths | grep "/$section" | grep "/$pagearg\." | sort | head -n1`
if [ -z $pagefile ]; then
echo -n No manual entry for $pagearg
[ $section ] && echo -n " in section $1 of the manual."
echo
exit
fi
#okay, found the page, try decompressing and displaying
case $pagefile in
*.bz2)
bzcat $pagefile | less ;;
*.gz)
zcat $pagefile | less ;;
*)
less $pagefile ;;
esac
#cleanup, just incase
paths=
pagefile=
pagearg=
section=
More information about the busybox
mailing list