test -n/-z的注意事项
2/13/2017来源:经验技巧人气:19761
有时会用到-n -z来判断字符串长度,用到变量是要小心。比较一下两条语句
[monitor@msg7 .monitor]$ if [ -n $b ];then echo yes;else echo no;fi yes [monitor@msg7 .monitor]$ if [ -n "$b" ];then echo yes;else echo no;fi no $b是未定义一个的变量,但是有引号和没引号,-n给出了不同的答案。所以要记得加引号,才能正确识别字符串变量的长度。
最新文章推荐