day52 Lecture Notes (shell variable string and arithmetic)

The first chapter, shell of special variables

$0  :   当前shell的脚本名字,执行脚本包含路径,那么就包含脚本路径
$n  :   获取脚本执行的时候接的参数,n大于9就用大括号括起来
$#  :   shell脚本后面接的参数总个数
$*  :   获取当前shell脚本所有传参的参数,加引号“$*”表示将所有的参数视为单个字符串
$@  :  不加引号和$*输出结果相同,加引号“$@”表示将所有参数视为不同的独立字符串
$?  :   判断上一个命令是否执行成功
$$  :   获取当前执行shell脚本的进程号(PID)
$!  :   获取上一个脚本进程号
$_  :   获取在此之前执行的命令或脚本的最后一个参数
16837788-31d28e929245bc60.png
image.png
16837788-b23305f03c595997.png
image.png
16837788-5736d08789523222.png
image.png
16837788-dd74fe59245a27e0.png
image.png
16837788-a1101c2540f5ebda.png
image.png

The second chapter, shell variable string

2.1, delete

16837788-47e1b0defe745f2d.png
16837788-94da4ea77ca5f40a.png
image.png

16837788-0dff2c9f895e1eeb.png
image.png

2.2, the output content to be replaced, replace the equivalent sed

16837788-7d45eccc51e58dac.png
image.png
16837788-bc4b8cb49120d609.png
image.png

2.3, the content acquisition variable length method

16837788-a300dc290d93c4fb.png
image.png

The third chapter, shell special variable expansion

16837788-7ffb7c715f64a8c0.png
image.png

The fourth chapter, the common arithmetic operators

16837788-5b506c1aaabc6dda.png
image.png

Chapter V, shell common operational command

16837788-987ef8df66f505f9.png
image.png

5.1, numerical operations (integer arithmetic)

the first method,(())

16837788-d7e33ffe631b76a5.png
image.png

The second method, let

16837788-eeac55b4c789c223.png
image.png

The third method, expr

16837788-bc98c877b0c1ebad.png
image.png

The fourth method, $ []

16837788-2187edf9c3474777.png
image.png

The fifth method, declare -i

16837788-a58fce640c9283c5.png
image.png

5.2, integer or fractional arithmetic

The first, awk algorithm

16837788-1eeb554f23c113ea.png
image.png

The second, bc calculator

16837788-dc471336767b922e.png
image.png

5.3、a++、a--

16837788-77913b8a7e8e0783.png
image.png

5.4, ​​(()) is determined

16837788-734b6637ceec7095.png
image.png

5.5, expr function

16837788-6d3946389150c13f.png
image.png

16837788-6fb0d54ebb63a4cd.png
image.png

5.6, the essence is to read read variable assignment

 变量赋值的三种方式:
  1)定义式 a=1
  2)  read读入式
 3)脚本传参  $1=100
16837788-705fd7ded125fb80.png
image.png

Chapter VI, grammar test conditions (now determine whether there is)

      文件测试表达式:对文件的属性进行判断,然后根据结果进行处理
16837788-f40a2f80431c52ce.png
image.png
16837788-7862606c87e067ee.png
image.png
16837788-7b6d3ba0684a965e.png
image.png

16837788-1fc44974351f0ad3.png
image.png

16837788-35c26abff7d99e2c.png
image.png

6.1, [] brackets

16837788-98104c94d9bd834e.png
image.png

16837788-287edf8b87eadb34.png
image.png

6.2, condition parameter expressions

16837788-bb9515c5236672c6.png
image.png

16837788-00432126a363a106.png
image.png

6.3, a string expression

16837788-8adcc771ca26681b.png
image.png

16837788-fbb151fd0a105331.png
image.png

16837788-3e8151c1a1692e76.png

Guess you like

Origin blog.csdn.net/weixin_34320724/article/details/90907497