Determine if a string is empty inside the shell

Source: Internet
Author: User
determine if a string is empty inside the shell Category: Linux shell2011-12-28 23:18 15371 people read reviews (0) favorite report Shell

There are several main ways to do this:

echo "$str" |awk ' {print length ($)} '
Expr Length "$str"
echo "$str" |wc-c
But the third kind of value will be 1 more, maybe the Terminator is also counted.

There are three ways to determine if a string is empty:
If ["$str" = ""]
If [x "$str" = x]
If [-Z ' $str '] (-n is not null)
Note: You have to double quotation marks, or some commands will be error, form a good habit!

Determine if a string is empty inside the shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.