1、command解釋
command指令在shell腳本裡面,如果發現有個函數和我們需要執行的指令同名,我們可以用command用來強制執行後面的指令,而不是同名函數,然後我們也可以在shell腳本裡面判斷莫個指令是否存在,我們平時一般用which指令也行。
2、測試代碼
#!/bin/bash
function pwd()
{
echo "I am pwd function"
}
echo "shell run pwd"
pwd
echo "shell command pwd"
command pwd
if command -v pwd > /dev/null; then
echo "pwd command has found"
else
echo "pwd command has not found"
fi
if command -v pwd1 > /dev/null; then
echo "pwd1 command has found"
else
echo "pwd1 command has not found"
fi
3、運作結果
./command
shell run pwd
I am pwd function
shell command pwd
/home/chenyu/Desktop/linux/dabian/python
pwd command has found
pwd1 command has not found