我正在尝试执行一个bash脚本,它只为我提供"n“命令的第一行man。
示例:
$ sh ./start.sh ls wazup top
ls - list directory contents
wazup - manpage does not exist
top - display Linux tasks这是我当前的代码:
! 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我的输出是:
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发布于 2013-03-03 07:39:30
检查man返回的状态代码,而不是在通过head和tail管道传输之后(这将是错误的,因为它将是tail的返回状态)。
发布于 2013-03-03 08:00:19
非常感谢Alex!
通过在您的帮助下不使用管道解决了这个问题!:)
以下是我为任何需要它的人提供的最终代码:
#!/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
donehttps://stackoverflow.com/questions/15180704
复制相似问题