Check whether the string is empty in the Linux Shell

There are mainly the following methods:

echo "$str"|awk '{print length($0)}'
expr length "$str"
echo "$str"|wc -c
But the value of the third one will be 1 more, It may be that the terminator is also counted. There are three ways to

judge string is empty:
if [ "$str" = "" ]
if [ x"$str" = x ]
if [ -z "$str" ]
Note : must substitute double quotes, otherwise some commands will report errors, so form a good habit!

Guess you like

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