Linux-shell Test

Source: Internet
Author: User

The nature of the test:

is an action command

Determine if the condition is true based on the $? return value


Operating Specifications:

Format 1:test conditional expression

Format 2: [Conditional expression]


Contact method for the test operation:

Direct root && echo YES to determine results

Usage: [conditional expression] && echo YES


Test examples:

[-D "/etc/fstab"] && echo YES

[-D "/boot/fstab"] && echo YES

[-F "/etc/fstab"] && echo YES

[-F "/boot"] && echo YES

Presence and Identification:

-E: Whether the target exists

-D: Whether it is a directory

-F: Whether it is a file


Detection of permissions:

-r: Read permission

-W Write permission

-X whether there are executable (excute) permissions


Integer value comparison:

-eq Equals (equal)

-ne not equal to (not equal)

-GT greater than (greater than)

-lt less than (lesser than)

-ge greater than or equal to (greater or equal)

-le less than or equal to (lesser or equal)


Integer value comparison:

[$ (who | wc-l)-eq 2] && echo YES


[$USER = "root"] && echo YES

Linux-shell Test

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.