Solution to the "integer expression expected" of the shell command __shell

Source: Internet
Author: User

In the shell script, when comparing with parameters, such as "[$temp-eq" IPhone "]", there may be an "integer expression expected" error. This is because these parameters:-GT,-lt,-eq comparisons are both numbers and variables, so the variable temp if it is a string, this error occurs. Change the original sentence to "[$temp-eq IPhone]" and the result is the same.

To solve this problem, we can take a more circuitous approach, that is, use the awk tool to compare the variables, return the results of comparisons, and compare the results with the corresponding numbers. The above examples can be handled in this way:

[' Echo ${temp} | awk-v tem= ' iPhone ' {print ($1>tem)? "1": "0"} '-eq "0"]

Full version:

If [' Echo ${var} | awk-v tem= ' iphone9,2 ' {print ($1>tem)? "1": "0"} '-eq "0"]
then 
     echo iPhone 7 Plus
else echo unrecognized
     device
fi
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.