首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于具有自定义输出的man的bash脚本

用于具有自定义输出的man的bash脚本
EN

Stack Overflow用户
提问于 2013-03-03 07:36:09
回答 2查看 97关注 0票数 3

我正在尝试执行一个bash脚本,它只为我提供"n“命令的第一行man。

示例:

代码语言:javascript
复制
$ sh ./start.sh ls wazup top 
ls - list directory contents
wazup - manpage does not exist
top - display Linux tasks

这是我当前的代码:

代码语言:javascript
复制
! bin/bash/
while [ -n "$1" ]
do
which $1> /dev/null
man $1 | head -6 | tail -1
if [ $? = 0  ]
then
echo "manpage does not exist"
fi
shift
done

我的输出是:

代码语言:javascript
复制
ls - list directory contents
manpage does not exist
No manual entry for wazzup
manpage does not exist
top - display Linux processes
manpage does not exist
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-03 07:39:30

检查man返回的状态代码,而不是在通过headtail管道传输之后(这将是错误的,因为它将是tail的返回状态)。

票数 2
EN

Stack Overflow用户

发布于 2013-03-03 08:00:19

非常感谢Alex!

通过在您的帮助下不使用管道解决了这个问题!:)

以下是我为任何需要它的人提供的最终代码:

代码语言:javascript
复制
#!/bin/bash
while [ -n "$1" ]
do
which $1> /dev/null
if [ $? = 0 ]
then
man -f $1
else 
echo "$1: manpage does not exist" 
fi
shift
done
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15180704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档