Linux 使用bash从手册页中为给定的退出代码提取特定行
我希望在给定有效退出代码的情况下,从手册页的退出代码部分返回一行特定的代码 例如,如果我在脚本中运行curl,它返回的退出代码为2,我想从curl手册页返回以下行:Linux 使用bash从手册页中为给定的退出代码提取特定行,linux,bash,shell,unix,grep,Linux,Bash,Shell,Unix,Grep,我希望在给定有效退出代码的情况下,从手册页的退出代码部分返回一行特定的代码 例如,如果我在脚本中运行curl,它返回的退出代码为2,我想从curl手册页返回以下行: 2 Failed to initialize. 到目前为止,我已经尝试将man curl的输出通过管道传输到grep,如下所示: 假设运行curl命令后,$RETCODE=${?} lewis@hostname:~$ man curl | grep "${RETCODE}" http://www.l
2 Failed to initialize.
到目前为止,我已经尝试将
man curl
的输出通过管道传输到grep,如下所示:
假设运行curl命令后,$RETCODE=${?}
lewis@hostname:~$ man curl | grep "${RETCODE}"
http://www.letters.com/file[a-z:2].txt
in the format "NAME1=VALUE1; NAME2=VALUE2".
out to be in text mode for win32 systems.
from outputting that and return error 22.
re-use the same IP address it already uses for the control connection. (Added in 7.14.2)
...
...
但这篇文章还收录了大量其他以数字为特征的文本。考虑到退出代码部分是缩进的,我已经尝试过了
lewis@hostname:~$ man curl | grep " ${RETCODE}"
2) On windows, if there is no _curlrc file in the home dir, it
2 Failed to initialize.
227-line.
21 FTP quote error. A quote command returned error from the server.
...
正如你所看到的,我们很接近。我想要的文本在那里,但它仍然返回不正确的结果
注意,对于带有两位或两位以上数字的退出代码,手册页中数字右侧的空白将减少。请尝试以下操作:
man curl | grep -E "^\s+${RETCODE}\s+"
试试这个:
man curl | grep -E "^\s+${RETCODE}\s+"
$mancurl | sed-n-e'/^e..X..I..T/,/^A..U..T..H/!d'-e'/2/p'
$mancurl | sed-n-e'/^e..X..I..T/,/^A..U..T..H/!d'-e'/2/p'
尝试:
尝试:
看起来不错,不过它返回的退出代码的第一个数字是
${RETCODE}
。2分23,就是这个!干杯,约翰。虽然有人比你先到达那里:(.看起来不错,尽管它返回的退出代码的第一个数字是${RETCODE}
。例如,23代表2。就是这个!干杯,约翰。尽管有人比你先到达那里:)谢谢,这对我试过的箱子很管用。谢谢,这对我试过的箱子很管用。
man curl | egrep " {7}${RETCODE} +\S+"