Linux self-study _shell script if detailed

Source: Internet
Author: User

1) What is the function of the IF condition control statement?

The shell script is also a weak scripting language and supports if conditional control statements.

2) If the structure syntax

Single Branch

If

Then

Fi

Dual Branch

If

Then

Else

Fi

Multi-Branch

If

Then

Elif

Then

Else

Fi

3) Scope of application

Determine if business services are functioning properly

Example

Determine if the LFTP is installed if not installed

VI install_lftp.sh

#!/bin/bash

Rpm-qa |grep lftp 1>/dev/null

If [$?-ne 0];then # #若上调命令执性不成功说明没有安装lftp, install

Yum-y Install lftp &>/dev/null &&echo "lftp installed."

Fi

: Wq

Expand "" One of the usages

When the variable is a number, it is to be judged by the numbers, and the state of the software is analyzed by the result.

Integer comparison

-eq equals, such as: if ["$a"-eq "$b"]

-ne not equal to, such as: if ["$a"-ne "$b"]

-GT greater than, such as: if ["$a"-gt "$b"]

-ge greater than equals, such as: if ["$a"-ge "$b"]

-lt less than, such as: if ["$a"-lt "$b"]

-le less than equals, such as: if ["$a"-le "$b"]


Linux self-study _shell script if detailed

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.