Shell matching a regular expression

Source: Internet
Author: User
Is_upper ()
# Is_upper
# Checks tosee if we have a string in upper case
# To Call: is_upper $1
{
# Check we have the right Params
If [$ #-ne 1]; then
Echo "is_upper: I need a string to test OK"
Return 1
Fi
# Use awk to check we have only uppercase
_ Is_upper = 'echo $1 | awk '{if ($0 ~ // [^ A-Z]/) print "1 "}''
If ["$ _ is_upper "! = ""]
Then
# No, they are not all uppercase
Return 1
Else
# Yes all uppercase
Return 0
Fi
}

# _ Is_upper = 'echo $1 | awk '{if ($0 ~ /[^ A-Z]/) print "1"} '''~ 'Indicates matching a regular expression, and [^ A-Z] indicates a character other than A-Z
So the meaning of this sentence is if the first parameter appears any character other than the A-Z (that is, not all uppercase letters), then print "1"
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.