Linux type命令:显示指定命令的类型
命令语法
type [-afptP] name [name ...]type [-afptP] name [name ...]type [-afptP] name [name ...]
命令作用
- 显示要查找的命令的信息。
- 控制查找范围和行为。
- 显示要查找的命令优先级最高的类型。
命令选项
- a:在环境变量PATH中查找并显示所有包含name的可执行文件路径;当’-p’选项没有同时给出时,如果在别名、关键字,函数,内建的信息中存在name,则一并显示。
- f:排除对shell函数的查找。
- p:如果name在执行’type -t name’返回的不是’file’,那么什么也不返回;否则会在环境变量PATH中查找并返回可执行文件路径。
- P:即使要查找的name是别名、内建、函数中的一个,仍然会在环境变量PATH中查找并返回可执行文件路径。
- t:根据name的类型返回一个单词(别名,关键字,函数,内建,文件),否则返回空值。
命令参数
- name:要查找的命令,可以为多个。
命令返回值
当指定的命令可以找到时返回成功,如果有没找到的返回失败。
接下来要用到的例子假设'~/.bashrc'文件定义了以下的内容:alias ls='ls --color=auto'test123(){ vim ~/.bashrc; }而且执行环境里没有使用enable禁用内建命令。接下来要用到的例子假设'~/.bashrc'文件定义了以下的内容: alias ls='ls --color=auto' test123(){ vim ~/.bashrc; } 而且执行环境里没有使用enable禁用内建命令。接下来要用到的例子假设'~/.bashrc'文件定义了以下的内容: alias ls='ls --color=auto' test123(){ vim ~/.bashrc; } 而且执行环境里没有使用enable禁用内建命令。
type -a test123test123 is a functiontest123 (){vim ~/.bashrc}type -a -f test123bash: type: test123: not foundtype -a -p test123type -a lsls is aliased to `ls --color=suto'ls is /usr/bin/lsls is /bin/lstype -a -p ls/usr/bin/ls/bin/lstype -a test123 test123 is a function test123 () { vim ~/.bashrc } type -a -f test123 bash: type: test123: not found type -a -p test123 type -a ls ls is aliased to `ls --color=suto' ls is /usr/bin/ls ls is /bin/ls type -a -p ls /usr/bin/ls /bin/lstype -a test123 test123 is a function test123 () { vim ~/.bashrc } type -a -f test123 bash: type: test123: not found type -a -p test123 type -a ls ls is aliased to `ls --color=suto' ls is /usr/bin/ls ls is /bin/ls type -a -p ls /usr/bin/ls /bin/ls
type -p printftype -P printf/usr/bin/printf/bin/printftype -p printf type -P printf /usr/bin/printf /bin/printftype -p printf type -P printf /usr/bin/printf /bin/printf
type -t lsaliastype -t forkeywordtype -t test123functiontype -t -f test123type -t printfbuiltintype -t chmodfiletype -t ls alias type -t for keyword type -t test123 function type -t -f test123 type -t printf builtin type -t chmod filetype -t ls alias type -t for keyword type -t test123 function type -t -f test123 type -t printf builtin type -t chmod file
注意
- 该命令是 bash 内建命令,相关的帮助信息请查看help命令。
- 命令优先级问题请查看builtin命令。
© 版权声明
本站文章由不念博客原创,未经允许严禁转载!
THE END