Linux environment to determine whether a string is not empty

Requirement description :

  Today, I helped a colleague adjust the script, which involves judging that a string is not empty, and record it here.

Operation process :

Use -n to determine whether the string is not empty, if it is not empty then it is true

#!/bin/bash

Str1='MyTest'

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

Execution result :

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

Note: After testing, the string is not empty, the judgment is true.

 

Document Creation Time: April 26, 2018 16:27:34

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324929085&siteId=291194637