Linux Shell if [n] Use method correctly __linux

Source: Internet
Author: User
if [str1 = str2] When two strings have the same content, the length is true
If [str1!= str2] True when string str1 and str2 are unequal
If [-N str1] is true when the length of the string is greater than 0 (string non-empty)
If [-Z str1] is true when the length of the string is 0 (empty string)
If [str1] is true when string str1 is Non-null

The shell uses-N to determine that the string is non-null.

Error usage:

args=$*

If [-N $ARGS]

Then

Print "with argument"

Fi

print "Without argument"

Regardless of the pass parameter, always enter the if inside.

Reason: Because the IF statement is equivalent to if [-N],shell will treat it as if [str1] without "", n is not null, so it is positive.

Correct usage: You need to add double quotes, or "$ARGS", to the $args.

args=$*

If [-N "$ARGS"]

Then

Print "with argument"

Fi

print "Without argument"


Copyright NOTICE: This article for the reprint article, originates from ciky2011, the copyright belongs to the original author all, welcome to share this article, reprint please reserve the source.

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.