- Bash Quick Start Guide
- Tom Ryder
- 342字
- 2021-07-23 16:58:58
The type command
The type command, given the name of any command or commands, gives you information about what kind of command it is:
bash$ type echo echo is a shell builtin bash$ type grep grep is /bin/grep
It identifies shell keyword, too:
bash$ type for for is a shell keyword
We can define a function and an alias to test that it correctly detects those:
bash$ myfunc() { : ; } bash$ type myfunc myfunc is a function
myfunc ()
{
:
}
bash$ alias myalias=: bash$ type myalias myalias is aliased to `:'
The type command has a few useful options. If you use the -t option, you can get a single word specifying the command type. This is sometimes useful in scripts:
bash$ type -t echo builtin bash$ type -t grep file
If you use the -a option, you can see all commands that have the same name. Bash will print them in order of preference. For example, the true name probably has both a builtin command and a system command on your system:
bash$ type -a true true is a shell builtin true is /bin/true
Bash will always prefer builtin commands for a given name over system commands. If you want to call the system's implementation of true, you could do it by specifying the full path to the program:
$ /bin/true
Another useful switch for type is -P, which will look for a system command for the given name, and print out the path to it if found:
bash$ type -P true /bin/true
Note that the /bin/true path was returned, even though true is also the name of a shell builtin.
There is a reason we put the type command first in this list. After help, it is the most useful Bash command for understanding the language, and clearing up the biggest source of confusion about the language: When I run this command, what is actually running?
- Ansible Configuration Management
- 自動控制工程設(shè)計入門
- 大型數(shù)據(jù)庫管理系統(tǒng)技術(shù)、應(yīng)用與實例分析:SQL Server 2005
- 大數(shù)據(jù)平臺異常檢測分析系統(tǒng)的若干關(guān)鍵技術(shù)研究
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- Enterprise PowerShell Scripting Bootcamp
- AI的25種可能
- 青少年VEX IQ機器人實訓(xùn)課程(初級)
- FANUC工業(yè)機器人配置與編程技術(shù)
- 基于Proteus的PIC單片機C語言程序設(shè)計與仿真
- 玩機器人 學(xué)單片機
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計實例詳解
- 大數(shù)據(jù):從基礎(chǔ)理論到最佳實踐
- R Statistics Cookbook