1. command
command有两个作用:
- 判断命令是否存在
- 如果shell脚本中,有与命令同名的函数,使用command,强行执行命令。
1.1 判断命令是否存在
tom@tom-linuxer:~$ command -v ls
alias ls='ls --color=auto'
tom@tom-linuxer:~$ $?
0:未找到命令
tom@tom-linuxer:~$ command -v ls1
tom@tom-linuxer:~$ $?
1:未找到命令
说明: 如果命令存在,command -v ,则返回结果0;如果不存在,则返回命令为1。
1.2 强制执行命令
tom@tom-linuxer:~$ ./test1.sh
shell run pwd
I am pwd function
shell command pwd
/home/tom
tom@tom-linuxer:~$ cat test1.sh
#!/bin/bash
function pwd()
{
echo "I am pwd function"
}
echo "shell run pwd"
pwd
echo "shell command pwd"
command pwd