首先要说明的是,不要使用which来进行判断,理由如下: 1.which非SHELL的内置命令,用起来比内置命令的开销大,并且非内置命令会依赖平台的实现,不同平台的实现可能不同. # type type type is a shell builtin # type command command is a shell builtin # type which which is hashed (/usr/bin/which) 2.很多系统的which并不设置退出时的返回值,即使要查找的命令不存在,…
test.sh #!/bin/bash echo "enter the string:" read filename if test $filename ; then echo "it's not zero" else echo "it's zero" fi 执行 sudo chmod +x test.sh ./test.sh 输出 enter the string: it's zero 执行 ./test.sh 输出 enter the str…
摘自:http://blog.51cto.com/lynnteng0/804520 describe="it's a describe by yourself" if echo "$describe" | grep -q '^[a-zA-Z0-9]\+$'; then echo "ok" else echo "invalid" fi describe="it's a describe by yourself"…