zoukankan      html  css  js  c++  java
  • [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呢。

  • 相关阅读:
    (原)torch中threads的addjob函数使用方法
    (原)torch中提示Unwritable object <userdata> at <?>.callback.self.XXX.threads.__gc__
    (原)luarocks更新某个模块
    EL表达式
    leetcode 151反转单词
    括号生成
    leetcode 机器人能到达的位置
    leetcode 翻转数组
    leetcode 460 LFU缓存
    leetcode 42 接雨水
  • 原文地址:https://www.cnblogs.com/cbscan/p/2309744.html
Copyright © 2011-2022 走看看