Shell Command expr and test command, shellexprtest

Source: Internet
Author: User

Shell Command expr and test command, shellexprtest

You can use the expr command to perform operations such as +,-, *, \, and %. However, when using multiplication, add a \ symbol before.

You can use the test command to perform a logic test. There are four testing cases:

1. Integer Test

A. Determine whether two integers are equal -- test int1-eq int2

B. Determine whether two integers are unequal -- test int1-ne int2

C. Determine whether integer 1 is greater than integer 2 -- test int1-gt int2

D. judge whether integer 1 is greater than or equal to integer 2 -- test int1-ge int2

E. Determine whether integer 1 is smaller than integer 2 -- test int1-lt int2

D. judge whether integer 1 is less than or equal to integer 2 -- test int2-le int2

2. String Testing

A. judge whether the string is null. If it is null, return true. If it is not null, return false: test-z string.

B. judge whether the string is not null. If it is not null, the return result is true. If it is null, the return result is false: test-n string.

C. Determine whether the two strings are equal: test str1 = str2

D. Determine whether the two strings are not equal: test str1! = Str2

3. File Test

A. Determine whether the user has the permission to read the file: test-r filename

B. Determine whether the user has the write permission for the file: test-w filename

C. Determine whether the user has the executable permission for the file: test-x filename

D. Determine whether the file is a normal file: test-f filename

E. Determine whether the file is a directory: test-d filename

F. Determine whether the file is capitalized and not zero: test-s filename

G. Determine whether the device is a block Device File: test-B filename.

4. logical operations

A. True if both expressions are true at the same time; otherwise false: test expression 1-a expression 2

B. either of the two expressions is true, and both are false: test expression 1-o expression 2

 

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.