2
如何檢查一個字符串是否包含命令或不在bash Linux中?檢查一個字符串是否包含命令?
我試圖做到這一點,但它不工作
read x ;
if [ $x -eq $0 ] ;then
echo x is a command
else
echo is a string;fi
任何一個可以幫助你們?
如何檢查一個字符串是否包含命令或不在bash Linux中?檢查一個字符串是否包含命令?
我試圖做到這一點,但它不工作
read x ;
if [ $x -eq $0 ] ;then
echo x is a command
else
echo is a string;fi
任何一個可以幫助你們?
任何字符串都可以是命令。 可以用做什麼,使用which
來找出這樣命名的可執行文件是否在$PATH
上。
檢查的輸出或退出狀態which $x
使用bash的內置type
read x
type "$x"
作用於結果:
if type "$x" &>/dev/null; then
# this is a builtin/function/alias/executable
else
# this is not
fi
http://www.gnu.org/software/bash/manual/bashref.html#index-type
你怎麼定義一個命令? – anubhava
@anubhava一個像ls,cat,cp,grep等等的linux命令 – JafarAlali92