Shell-based if statement

Source: Internet
Author: User

In determining the size of a value in addition to (()) can be used in the form of [] but can not use;, <, = such a symbol, to use-LT (less than),-GT (greater than),-le (less than equals),-ge (greater than or equal),-eq (equals),-ne (not equal) 。

If statement

if Judgment statement; Then

Command

Fi

If,else statements

if Judgment statement; Then

Command

Else

Command

Fi

If Elif statement

If Judgment statement one; Then

Command

Elif Judgment Statement two; Then

Command

Else

Command

Fi

Three examples:

[email protected] ~]# cat if1.sh

#/bin/bash

Read-p "Input your Source:" A

If [$a-lt];then

echo "You did notpass the exam"

elif [$a-ge]&&[$a-le 85]; Then

echo "You pass the exam"

Else

echo "Your source is very high"

Fi


If statement can determine file attributes and permissions

-E: Determine if a file or directory exists

-D: Determine if the directory is not present and whether it exists

-F: Determine if the file is normal and exists

-R: Determine if the document has Read permissions

-W: Determine if Write permission is available

-X: Determine if executable

-Z: To determine if the variable is empty if [-Z $a] is empty is true.

When you use the If judgment, the specific format is:

If [-e filename]; Then

Example:

[Email protected] ~]# if [-d/home/]; then echo OK; Fi

Ok


This article from the "title" blog, declined reprint!

Shell-based if statement

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.