Bash--file test, string comparison

Source: Internet
Author: User


File test: Need to add brackets

Whether the-e file exists

Whether the-f file is a normal file

Whether the-D file is a directory

-R file is readable for the current user

-W File Write

-X File Execution


Combination test:

-A and relationship

-O or relationship

! Non-relational

Writing:

If [$A-ge 4-a $A-lt 7]

If [$A-ge 4] && [$A-lt 7]

Greater than or equal to 4 and less than 7

If [$A-ge 4-o $A-lt 4]

If [$A-ge 4] | | [$A-lt 4]

Greater than or equal to 4 or less than 4


Fuzzy matching =~

Integer containing 4 in 1-100

i= ' seq 1 100 '

V=4

[[$I =~ $V]]




Judging file scripts (normal, directory, or other)

Read-p "Please input a file:" N

If [-F $N];then

echo "$N is Putong"

elif [-D $N];then

echo "$N is Mulu"

Else

echo "Bu Cunzai huo Feifa"

Fi

Exercise: Write two numbers to calculate the result of multiplying the two numbers together

#!/bin/bash
#
If [$#-lt 2];then
echo "Qing Xie Chu lia ge Shuzi"
Exit 8
Fi
echo "He wei $[$1+$2]"
echo "Ji Wei $[$1*$2]"



This article is from the "you and I Walk" blog, please be sure to keep this source http://ondali.blog.51cto.com/6650368/1615953

Bash--file test, string comparison

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.