Shell entry operator operation, conditional judgment

♥️Author : Xiao Liu at Station C

♥️Personal homepage:  Xiao Liu’s homepage 

♥️Efforts may not necessarily pay off, but there will definitely be gains! Come on! Work hard together for a better life!

♥️Learn the operation and maintenance experience summarized in two years, as well as the full set of network experiment tutorials on the Cisco simulator. Column: Cloud Computing Technology

♥️You can ask Xiao Liu in private messages as long as you know how to do it and you won’t be stingy. Thank you CSDN for letting you and I meet!

Table of contents

introduce

1.The origin of shell

2.What is shell

3.What can the shell do?

1. Operator

2. Conditional judgment


introduce

1.The origin of shell

    When Dennis Ritchie and Ken Thompson of AT&T designed UNIX™, they wanted to create a way for users to communicate with their new system.

    Operating systems back then had command interpreters. The command interpreter accepts commands from the user and interprets them so the computer can use them.

    But Ritchie and Thompson wanted more than just these features. They wanted to provide a tool with better functionality than the command interpreters of the time. This led to the development of the Bourne shell (commonly known as sh), created by SR Bourne. Since the creation of the Bourne shell, other shells have been developed, such as the C shell (csh) and the Korn shell (ksh).

    When the Free Software Foundation sought a free shell, developers began working on the language behind some of the most popular features in the Bourne shell and other shells at the time.

2.What is shell

The shell is a command interpreter. When it accepts application/user commands, it calls the operating system kernel for interpretation, so as to execute the commands we enter and obtain the results. In addition, the shell is a powerful programming language, easy to write, easy to debug, and highly flexible.

The shell acts as a translator between the hardware and the user. This is its role.

3.What can the shell do?

Shell can realize automated operation and maintenance, automated office, writing scripts, etc. in our life or office.

1. Operator

The operators and normal expressions in the shell do not work. Unlike other high-level programming languages, the shell can directly perform normal operations of addition, subtraction, multiplication and division, so operation statements are used.

语法1: echo   $((运算式)) 
语法2: echo   $[运算式]

The command word is "$(( ))" "$[ ]"

There must be spaces around the operator in the expression, such as: $((1 + 2))

Others (unpopular command words):

                Syntax: expr value operator value      

2. Conditional judgment

Basic syntax:          

语法1:test    condition
语法2:[condition]      注意:condition 前后要有空格
备注:条件非空即为true[atguigu] 返回true [] 返回false

Common Judgment Conditions

(1) Comparison between two integers

-eq is equal (equal) -ne is not equal (not equal)

-lt is less than (less than) -le is less than or equal to (less equal)

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

Column [8 -lt 9] //Judge whether 8 is less than 9

Note: If it is a comparison between strings, use the equal sign "=" to judge equality: use "!=" to judge inequality

     true=1 (false) false=0 (true)

Judge based on file permissions Judge based on file type

-r has read permission (read) -e file exists (existence)

-w has write permission (rite) -f The file exists and is a regular file (file)

-x has execution permission (execute) -d file exists and is a directory (directory)

[-r abc.txt] //Whether there is read permission

[-e /root/file] //Whether there is a file file under /root/

&&: Two conditions with numbers are true at the same time | The previous command is executed successfully, and the next command is executed

|| : The two conditions of the or sign meet one | the next command will be executed only after the previous command fails to execute

列:[$a  -lt  20] && echo "$a<20"  ||   echo "$a > 20"

♥️Attention is the motivation for my creation

♥️Like is the greatest recognition for me

♥️This is Xiaoliu, I am inspiring to do every article well, thank you everyone

Guess you like

Origin blog.csdn.net/lzl10211345/article/details/132732220