Shell file Number Comparison

Source: Internet
Author: User

Echo ' 1.2*2 ' |BC

++++++++++++++++ Digital Comparison
Mode 1:
Agm1=50
Agm2=60

If [3-eq 3-a ${agm1}-ne ${agm2}-a ${agm2}-gt ${agm1}-a ${agm1}-ge 50-a ${agm1}-lt ${agm2}-a ${AGM2}-le 60- o 4-GT 3]; Then
Echo ' Yes '
Else
Echo ' No '
Fi

Mode 2:
Agm1= ' ye '
Agm2= ' ye '

if [["$agm 1" = = "$AGM 2" && "$AGM 1" = = ' ye ' && 2 > 1 && 1 < 2]]; Then
Echo ' Yes '
Else
Echo ' No '
Fi

Note: String comparisons must be double-quoted

Summarize:
-F file is present
Whether the-D directory exists
-s file exists and is not empty
-E exists as a directory or file
-L whether shortcut link

-R file is readable
-W file is writable
-X file is executable

-eq is equal
-ne is not equal to
-ge is greater than or equal to
-GT is greater than
-le is less than or equal to
-lt is less than

-A and
-O or

[*] curly braces General letters available
[[*]] double braces General && | | > < >= <= = = = Match available

The above related can be explained in detail in Help test

Conditional control Statements


Get memory Size: free-m |grep buffers\/|awk ' {print $NF} '


Judge whether the number:
#!/bin/bash
Str= ' 123 '
[-N "' Echo ${str}|sed ' s#[0-9]# #g '"] && {
echo ' no int '
Exit 1
}

Or
[-N ' ' echo hello123|sed ' s/[0-9]//g ' "] && echo ' no int ' | | echo ' is int '

This article from the "Development and operation of the" blog, declined to reprint!

Shell file Number comparison

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.