关于linux:type查看Linux指令的类型

3次阅读

共计 670 个字符,预计需要花费 2 分钟才能阅读完成。

当咱们想要晓得 Linux 中一个指令的类型时,能够应用 type 指令。因为在 Linux 的 shell 中,有一些指令是 shell 内嵌的,有一些是内部的指令,当咱们想要辨别它们时,就能够应用 type 指令。

应用形式:

type [-tpaP] commandname

选项详解:
  • 当不带选项时,type 会显示命令是 bash 内嵌指令还是内部指令
  • -t:会显示以下几个关键词来示意指令的类型:

    • alias如果 commandname 是 alias
    • key-word如果 commandname 是 shell 的保留字
    • function如果 commandname 是函数
    • builtin如果 commandname 是 shell 内置的指令
    • file如果 commandname 是内部指令(disk file)
  • -p(小写):如果 commandname 是内部指令,即 type -t commandname 的返回值 是 file时,会显示 commandname 的残缺文件路径名(搜寻 PATH),如果 type -t commandname 的返回值 不是 file 时,则什么都不返回。
  • -P(大写):即便 type -t commandname 的返回值不是file(内部指令),也会强制搜寻 PATH 门路,即不管其是什么类型,都会返回残缺的文件路径名。
  • -a:会在 PATH 变量 规定的门路中搜查所有的 commandname 指令,包含 alias,并将其打印进去。

具体利用

type 对指令的搜寻都是在 PATH 门路下的,如果指令不在 PATH 规定的门路下,那么 type 不会有返回值的。
这是我简略测试得来的,如有谬误之处,还望各位小伙伴指出。

正文完
 0