linux shell 中判断字符串为空
-
-z 字符串:字符串的长度为零则为真
-
-n 字符串:字符串的长度不为零则为真
#!/bin/sh STRING= if [ -z "$STRING" ]; then echo "STRING is empty" fi if [ -n "$STRING" ]; then echo "STRING is not empty" fi
参考:
https://www.runoob.com/linux/linux-shell-test.html
https://www.cnblogs.com/cute/archive/2011/08/26/2154137.html