当前位置: 技术问答>linux和unix
请高手帮忙翻译一段shell代码
来源: 互联网 发布时间:2016-08-28
本文导语: 小弟是新手,麻烦高手帮忙解释这段shell 代码是什么意思,每一行都要,越详细越好。。谢谢。。 #!/bin/bash program=`basename $0` dm= for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man do if [ -d $d ]; then if...
小弟是新手,麻烦高手帮忙解释这段shell 代码是什么意思,每一行都要,越详细越好。。谢谢。。
#!/bin/bash
program=`basename $0`
dm=
for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man
do
if [ -d $d ]; then
if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi
fi
done
DEFMANPATH=$dm
dc=
for d in /usr/man/preformat /usr/man /usr/share/man/preformat /usr/share/man
do
if [ -d $d ]; then
if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi
fi
done
DEFCATPATH=$dc
DEFWHATISDIR=/var/cache/man
DEFWHATIS=$DEFWHATISDIR/whatis
AWK=/bin/awk
if TMPFILE=$(mktemp /tmp/whatis.XXXXXX)
then
trap "rm -rf $TMPFILE" 0
trap "rm -rf $TMPFILE; exit 255" 1 2 3 15
findarg0="-type f -size +0"
topath=manpath
defmanpath=$DEFMANPATH
defcatpath=
if [ -n "$MANSECT" ]; then
sections=$MANSECT
else
sections=`$AWK '($1 == "MANSECT") { print $2 }' /etc/man.config`
if [ x"$sections" = x ]; then
sections="1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l:p:o"
fi
fi
sections=`echo $sections | sed -e 's/:/ /g'`
whatisdb=$DEFWHATIS
for name in "$@"
do
if [ -n "$setsections" ]; then
setsections=
sections=$name
continue
fi
if [ -n "$setwhatis" ]; then
setwhatis=
whatisdb=$name
continue
fi
case $name in
--version|-V)
echo "$program from man-1.6f"
exit 0;;
-c) topath=catpath
defmanpath=
defcatpath=$DEFCATPATH
continue;;
-s) setsections=1
continue;;
-o) setwhatis=1
continue;;
-U) [ -f "$whatisdb" ] && findarg="-cnewer $whatisdb"
update=1
continue;;
-u) findarg="-ctime 0"
update=1
continue;;
-v) verbose=1
continue;;
-w) manpath=`man --path`
catpath=$manpath
continue;;
-*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]] [-o whatisdb]"
echo " This will build the whatis database for the man pages"
echo " found in manpath and the cat pages found in catpath."
echo " -s: sections (default: $sections)"
echo " -u: update database with pages added today"
echo " -U: update database with pages added since last makewhatis run"
echo " -v: verbose"
echo " -o: location of whatis database (default: $DEFWHATIS)"
echo " -w: use manpath obtained from `man --path`"
echo " [manpath]: man directories (default: $DEFMANPATH)"
echo " [catpath]: cat directories (default: the first existing"
echo " directory in $DEFCATPATH)"
exit;;
*) if [ -d $name ]
then
eval $topath="$$topath":$name
else
echo "No such directory $name"
exit
fi;;
esac
done
manpath=`echo ${manpath-$defmanpath} | tr : ' '`
if [ x"$catpath" = x ]; then
for d in `echo $defcatpath | tr : ' '`
do
if [ -d $d ]; then catpath=$d; break; fi
done
fi
catpath=`echo ${catpath} | tr : ' '`
#!/bin/bash
program=`basename $0`
dm=
for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man
do
if [ -d $d ]; then
if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi
fi
done
DEFMANPATH=$dm
dc=
for d in /usr/man/preformat /usr/man /usr/share/man/preformat /usr/share/man
do
if [ -d $d ]; then
if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi
fi
done
DEFCATPATH=$dc
DEFWHATISDIR=/var/cache/man
DEFWHATIS=$DEFWHATISDIR/whatis
AWK=/bin/awk
if TMPFILE=$(mktemp /tmp/whatis.XXXXXX)
then
trap "rm -rf $TMPFILE" 0
trap "rm -rf $TMPFILE; exit 255" 1 2 3 15
findarg0="-type f -size +0"
topath=manpath
defmanpath=$DEFMANPATH
defcatpath=
if [ -n "$MANSECT" ]; then
sections=$MANSECT
else
sections=`$AWK '($1 == "MANSECT") { print $2 }' /etc/man.config`
if [ x"$sections" = x ]; then
sections="1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l:p:o"
fi
fi
sections=`echo $sections | sed -e 's/:/ /g'`
whatisdb=$DEFWHATIS
for name in "$@"
do
if [ -n "$setsections" ]; then
setsections=
sections=$name
continue
fi
if [ -n "$setwhatis" ]; then
setwhatis=
whatisdb=$name
continue
fi
case $name in
--version|-V)
echo "$program from man-1.6f"
exit 0;;
-c) topath=catpath
defmanpath=
defcatpath=$DEFCATPATH
continue;;
-s) setsections=1
continue;;
-o) setwhatis=1
continue;;
-U) [ -f "$whatisdb" ] && findarg="-cnewer $whatisdb"
update=1
continue;;
-u) findarg="-ctime 0"
update=1
continue;;
-v) verbose=1
continue;;
-w) manpath=`man --path`
catpath=$manpath
continue;;
-*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]] [-o whatisdb]"
echo " This will build the whatis database for the man pages"
echo " found in manpath and the cat pages found in catpath."
echo " -s: sections (default: $sections)"
echo " -u: update database with pages added today"
echo " -U: update database with pages added since last makewhatis run"
echo " -v: verbose"
echo " -o: location of whatis database (default: $DEFWHATIS)"
echo " -w: use manpath obtained from `man --path`"
echo " [manpath]: man directories (default: $DEFMANPATH)"
echo " [catpath]: cat directories (default: the first existing"
echo " directory in $DEFCATPATH)"
exit;;
*) if [ -d $name ]
then
eval $topath="$$topath":$name
else
echo "No such directory $name"
exit
fi;;
esac
done
manpath=`echo ${manpath-$defmanpath} | tr : ' '`
if [ x"$catpath" = x ]; then
for d in `echo $defcatpath | tr : ' '`
do
if [ -d $d ]; then catpath=$d; break; fi
done
fi
catpath=`echo ${catpath} | tr : ' '`
|
楼主 已经发你邮箱了
|
好长。看不懂,顶了