[Unix]根据man生成所有命令的说明文档

一段shell脚本,放在linux中运行,会自动枚举/bin、/usr/bin等目录下的所有可执行文件,然后查找man生成html的说明文档。

生成的文档包中index.html是目录。

这包文档可以用在无man而又想使用unix tools的时候,如在windows下玩grep。

#! /bin/bash

helpDir=man_pages
main_file=./$helpDir/index.html
cmds=`
{
for j in ${PATH//:/ }
do
ls $j
done
} | sort | uniq `


rm -f -r $helpDir
mkdir $helpDir

echo "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> " >> $main_file
echo "<table border=\"1\"><tr><th>命令</th><th>描述</th></tr>" >> $main_file

for i in $cmds
do
echo "processing \"$i\"..."

file=./$helpDir/${i}.html

echo "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> " >> $file
echo "<p><a href="index.html">返回目录</a></p>" >> $file
echo "<hr>" >> $file
echo "<pre>" >> $file

man $i >> $file 2>/dev/null &&
{
echo "</pre>" >> $file

describ=`sed -n -e '/NAME/ {n;p;q}' $file | cut -f 2 -d '-'`

echo "<tr>" >> $main_file
echo "<td><a href=\"$i.html\">$i</a></td>" >> $main_file
echo "<td>$describ</td>" >> $main_file
echo "</tr>" >> $main_file
} ||
rm $file

done

echo "</table>" >> $main_file

仅46行啊,感慨一下shell脚本的信息密度之高!46行的c语言还在hello world呢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值