gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 09:28:35 24 4
gpt4 key购买 nike

我正在尝试编写一个 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

最佳答案

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

关于具有自定义输出的 man 的 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15180704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com