Determines whether a parameter is an integer in shell.

Source: Internet
Author: User
Tags arithmetic operators

Determines whether the parameter is an integer.
#! /Bin/bash </P> <p> function inttest () <br/> {<br/> for Arg <br/> DO <br/> # Arithmetic Operators, when the parameter is an integer, the execution fails. <br/> ($ Arg) 2>/dev/null # blocking error information <br/> If [$? = 0] <br/> then <br/> echo "$ Arg" is an integer <br/> else <br/> echo "$ Arg" is not an integer <br /> fi <br/> done <br/>}< br/> inttest-100 1234 22222222222222222 0765 0x10a + 100/<br/> 0 xaadg ASSD 1.00 200.0 2A70 0.00

Execution result:
-100 is an integer
1234 is an integer
22222222222222222 is an integer
0765 is an integer
0x10a is an integer
+ 100 is an integer
0 xaadg is not an integer
ASSD is not an integer
1.00 is not an integer
200.0 is not an integer
2A70 is not an integer
0.00 is not an integer

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.