html tool

2013年4月25日星期四

linux shell if 判断是否为空字符串



  • 参考来源:http://www.linuxsir.org/bbs/thread274765.html

    方法一:
    if [ -z $res ];then
           echo "${res} is null"
    [popexizhi]看到有帖子说应该是-z “$res” 才对,但自己的是从ps aux中拼凑出来的,没有这个问题,可以用的
    方法二:
    if [ "" == "$res" ];then
           echo "${res} is null"
    [popexizhi]原来自己一直写 “” == $res ,但是没有效果,现在明白了 如果$res是空 就成为 “”== 空,很明显不对,只有$res为“”才相等的,所以要在左边补上“”    

没有评论:

发表评论