Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux shell basic Grammar Amur2

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Amur1 talked about some basic grammar, and A2 continues what it said last time.

Shell is a programming language, and naturally there are structured representations. The common programming language structure is judgment and loop. The judgment in shell can be divided into three categories: numerical judgment, character judgment and file judgment.

Several forms of judgment

If command

Then

Command

FiIf command

Then

Command

Else

Command

Fi

If command

Then

Command

Elif command

Then

Command

Else

Command

Fi

(1) numerical judgment

Example: simple guessing of numbers

(2) character judgment

Example: determine the input option

(3) document judgment

Example: check whether the destination path exists before creating the log file

#! / bin/bash

If [!-d / mnt/123testlog/2019-08-31]

Then

Mkdir-p / mnt/123testlog/2019-09-31

Fi

Still need to pay attention to

The usage of If test xxxx

The parameters are worth judging and dealing with.

Compound condition judgment

If [] & & []

If [] | | []

Double parentheses

-- double parentheses (advanced features of mathematical expressions)

-- double parentheses (string advanced features)

It is more complicated to use if structure in multi-choice judgment, and it is better to use case.

Case

Case xxx in

P1)

Cmd

P2)

Cmd

*)

Default cmd

Esac

You can use case when dealing with the input parameters of the script, and then shift the parameters

Input can also be processed as follows, and the usage of getopt and getopts will be described in more detail later.

Getopt

Getopts

Read

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report