linux环境判断字符串是否为非空

需求描述:

  今天帮同事调整脚本,涉及到判断一个字符串为非空的,在此记录下.

操作过程:

通过-n来判断字符串是否为非空,如果为非空那么就是真

#!/bin/bash

Str1='MyTest'

if [[ -n $Str1 ]];then
  echo "$Str1 is not empty."
fi

执行结果:

[am@hadoop3 scripts]$ sh test.sh 
MyTest is not empty.

备注:经过测试,字符串不是空,判断是真了.

文档创建时间:2018年4月26日16:27:34

猜你喜欢

转载自www.cnblogs.com/chuanzhang053/p/8953348.html