如何获得“echo”或其他bash命令的帮助?

man echo工作。 但出于好奇,echo是否有类似于--help标志/参数的东西?

假设您正在使用bash, echo是一个内置的shell(您可以通过运行type echo看到)。 这意味着你想要阅读的man-page是man bash 。 或者你可以通过内置的help获得关于bash内置函数和关键字的help ,例如help echo

运行man echo时看到的信息是由GNU coreutils安装的外部echo命令。 ( type -a echo )。

要学习bash,请阅读http://mywiki.wooledge.org/BashGuide

有两个echo内置命令和另一个,一个可执行文件放在/ bin / echo中

内置(这是默认的)没有任何帮助选项远远超出内置的help echo 。 放置但未列出的任何标志都显示为命令结果,并且没有帮助命令。

在可执行版本而不是/bin/echo有一个--help标志来打印使用情况。 但你必须明确调用/bin/echo

其他方式是使用whatis bash命令。

 whatis echo >>>> shows as following echo (1) - display a line of text 

根据Whatis手册页,它显示手册页描述。 如

  whatis whatis whatis (1) - display manual page descriptions 

对于命令简要参数或选项,尝试--usage它们的前面的

 whatis --usage Usage: whatis [-dvrwl?V] [-C FILE] [-L LOCALE] [-m SYSTEM] [-M PATH] [-s LIST] [--debug] [--verbose] [--regex] [--wildcard] [--long] [--config-file=FILE] [--locale=LOCALE] [--systems=SYSTEM] [--manpath=PATH] [--sections=LIST] [--section=LIST] [--help] [--usage] [--version] KEYWORD... 

另一个很好的来源是Ubuntu Manuals aka manpage ,只需键入以搜索你想要的内容。

如果您在终端中尝试使用whatis并成功按下Tab键 ,则会显示该建议

 Display all 9747 possibilities? (y or n) 

您可以根据上述可能性进行实验。

还有类似于man -k keyword用于搜索手册页名称和描述的apropos

您还可以使用whereis来查找命令的二进制文件,源文件和手动页面文件

 whatis whereis whereis (1) - locate the binary, source, and manual page files for a command 

官方参考

您可以在Ubuntu Command Line Wiki页面上参考这个广泛优秀的源代码,例如[ 7. Beginners / BashScripting ]。

请参阅GNU Shell内置命令指南

对于外部来源参考

Linux的Bash命令行的AZ索引,解释示例和用法

O’reilly Linux命令目录来自Linux in a Nutshell,第5版

您可以使用help命令,因为这是一个内置的bash,这在脚本编写时有很多帮助

 [11:16:07 oyrm ~]$ help GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu) These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. Use `info bash' to find out more about the shell in general. Use `man -k' or `info' to find out more about commands not in this list. .... 

此横幅后面是命令列表,如横幅中所示。 试用

 help echo 

我想你会看到这是一个很好的,简洁的shell命令应用程序描述