linux的帮助系统之help

help是内部命令的帮助命令。主要有三个比较常用的选项:

1.-d 用来显示命令的描述信息;

2.-s 用来显示命令的语法信息;

3.-m 以manpage风格方式显示帮助信息;

4.还有一个是不带选项的显示;

下面以source命令的帮助信息为例:

1-1显示命令的描述信息:

[root@localhost ~]# help -d source
source - Execute commands from a file in the current shell.
[root@localhost ~]# 
[root@localhost ~]# 

2-2显示命令的语法信息:
[root@localhost ~]# help -s source
source: source filename [arguments]
[root@localhost ~]# 
[root@localhost ~]# 

3-3 以manpage风格显示命令的帮助信息:

[root@localhost ~]# help -m source
NAME
    source - Execute commands from a file in the current shell.


SYNOPSIS
    source filename [arguments]


DESCRIPTION
    Execute commands from a file in the current shell.
    
    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.
    
    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.


SEE ALSO
    bash(1)


IMPLEMENTATION
    GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
    Copyright (C) 2009 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

4-4 不带选项的help命令帮助:

[root@localhost ~]# help source
source: source filename [arguments]
    Execute commands from a file in the current shell.
    
    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.
    
    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.

除上面的使用外,还有几个技巧值得了解的:

在help中也支持glob风格的通配符匹配,这样的好处是只查看我们相看的内容,举例如下:

[root@localhost ~]# help -d read
read - Read a line from the standard input and split it into fields.
readarray - Read lines from a file into an array variable.
readonly - Mark shell variables as unchangeable.

从上面我们看到,打印出了三条命令的帮助,实际上我们只想查看read的用法,怎么办?

[root@localhost ~]# help -d "rea?"
Shell commands matching keyword `rea?'


read - Read a line from the standard input and split it into fields.

这样就可以达到目的

[root@localhost ~]# help -s "rea?"
Shell commands matching keyword `rea?'


read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
[root@localhost ~]# help -m "rea?"
Shell commands matching keyword `rea?'


NAME
    read - Read a line from the standard input and split it into fields.


SYNOPSIS
    read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]


DESCRIPTION
    Read a line from the standard input and split it into fields.
    
    Reads a single line from the standard input, or from file descriptor FD
    if the -u option is supplied.  The line is split into fields as with word
    splitting, and the first word is assigned to the first NAME, the second
    word to the second NAME, and so on, with any leftover words assigned to
    the last NAME.  Only the characters found in $IFS are recognized as word
    delimiters.
    
    If no NAMEs are supplied, the line read is stored in the REPLY variable.
    
    Options:
      -a array  assign the words read to sequential indices of the array
                variable ARRAY, starting at zero
      -d delim  continue until the first character of DELIM is read, rather
                than newline
      -e                use Readline to obtain the line in an interactive shell
      -i text   Use TEXT as the initial text for Readline
      -n nchars return after reading NCHARS characters rather than waiting
                for a newline, but honor a delimiter if fewer than NCHARS
                characters are read before the delimiter
      -N nchars return only after reading exactly NCHARS characters, unless
                EOF is encountered or read times out, ignoring any delimiter
      -p prompt output the string PROMPT without a trailing newline before
                attempting to read
      -r                do not allow backslashes to escape any characters
      -s                do not echo input coming from a terminal
      -t timeout        time out and return failure if a complete line of input is
                not read withint TIMEOUT seconds.  The value of the TMOUT
                variable is the default timeout.  TIMEOUT may be a
                fractional number.  If TIMEOUT is 0, read returns success only
                if input is available on the specified file descriptor.  The
                exit status is greater than 128 if the timeout is exceeded
      -u fd             read from file descriptor FD instead of the standard input
    
    Exit Status:
    The return code is zero, unless end-of-file is encountered, read times out,
    or an invalid file descriptor is supplied as the argument to -u.


SEE ALSO
    bash(1)


IMPLEMENTATION
    GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
    Copyright (C) 2009 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

查询所有内置的帮助语法:

[root@localhost ~]# help -s "*"

查询所有内置命令的帮助描述信息:

[root@localhost ~]# help -d "*"

以manpage方式查询所有内置命令的详细信息:

[root@localhost ~]# help -m "*"


直接 敲一个help命令后出现的所有的内置命令的信息

[root@localhost ~]# help 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值