shell

shell

01.shell 概述

image-20250715202158654

image-20250715203816144

image-20250715203958707

image-20250715204123990

image-20250715204148290

image-20250715204252594

image-20250715204647836

image-20250715204824496

02.编写格式和执行方式

image-20250715205104771

image-20250715205208620

image-20250715205309762

image-20250715205705916

image-20250715205725154

image-20250715205836801

image-20250715210016429

03.多命令处理

image-20250715210250933

image-20250715210437332

image-20250715210702543

image-20250715210622212

04.环境变量

image-20250715210934661

image-20250715211115200

image-20250715211248874

image-20250715211327225

image-20250715211350851

image-20250715211509749

image-20250715211553630

image-20250715211723266

image-20250715211906910

image-20250715212030968

image-20250715212103648

05.自定义局部变量

image-20250715212232659

image-20250715212508115

image-20250715212620452

image-20250715212726655

image-20250715212857161

image-20250715213007593

image-20250715213029836

06.自定义常量

自定义常量设置值以后不可以修改的变量叫常量,也叫只读变量 readonly

image-20250715213447977

07.自定义全局变量

image-20250715213808895

image-20250715214014579

#!/bin/bash
# demo2.sh
VAR4="mpp" # 非全局变量, 子 shell 中无法读取
export VAR4="MOO"  # export 关键字声明,自定义全局变量, 子shell 中可以调用
sh demo3.sh
#!/bin/bash
echo "demo3.sh 文件中输出变量VAR4,值为:${VAR4}"

image-20250715214823666

08.特殊符号变量

1.$n

image-20250715215124374

image-20250715215313365

image-20250715215528312

image-20250715215651730

2.$#

image-20250715215801503

image-20250715215836456

image-20250715220213234

3.$* 和 $@

image-20250715220607791

image-20250715220746554

image-20250715221023658

image-20250715221129312

4.$?

image-20250715221405146

image-20250715221452878

5.$$

image-20250715221711458

image-20250715221640552

image-20250715222009221

09.shell环境变量深入:自定义系统环境变量

image-20250716214320339

image-20250716214517947

在 vim 命令模式下 G 定位到 文本末尾, gg 定位到文本开头

image-20250716215009281

10.shell环境变量深入:加载流程原理

image-20250716215400328

image-20250716215719562

·

image-20250716215958351image-20250716220140729

image-20250716220336584

11.shell 环境变量深入:加载流程测试

image-20250716220614757

image-20250716220814348

image-20250716221308538

image-20250716221456806

image-20250716221835116

image-20250716221955657

12.shell 环境变量深入: 设别shell 环境类型

image-20250716222144697

image-20250716222403483

13.shell 环境变量深入:详细切换shell 环境

image-20250716222514613

image-20250716222609685

image-20250716222717443

image-20250716222759367

14.shell字符串变量:格式介绍

image-20250716222938780

image-20250716223035018

image-20250716223339080

image-20250716223441940

image-20250716223643485

image-20250716223804778

15.shell 字符串变量:拼接

image-20250716223913487

image-20250716224055032

image-20250716224135861

16.shell 字符串变量:字符串截取

image-20250716224230053

image-20250716224243904

image-20250716224707221

image-20250716224811232

17.shell 索引数组变量:定义-获取-拼接-删除

image-20250719160954728

image-20250719161108863

image-20250719161253090

image-20250719161500869

image-20250719161741579

image-20250719161917752

image-20250719162036847

image-20250719162232972

image-20250719162416099

18.shell内置命令:alias 设置别名

image-20250719162513915

image-20250719162628190

image-20250719163255595

image-20250719163509832

image-20250719163830529

19.shell内置命令:echo 输出字符串

image-20250719163952619

image-20250719164237048

image-20250719164419221

image-20250719164445662

image-20250719164533615

image-20250719164726696

20.shell 内置命令:read读取控制台输入

image-20250719164837069

image-20250719165231940

image-20250719165128957

image-20250719165332611

image-20250719165632844

image-20250719165735707

image-20250719165937911

image-20250719170148380

image-20250719170256993

image-20250719170318322

image-20250719170600853

image-20250719170756857

image-20250719170838761

image-20250719170959345

21.shell 内置命令:exit 退出

image-20250719171218030

image-20250719171326264

image-20250719171404459

image-20250719171523264

image-20250719171858934

image-20250719171924873

image-20250719172006224

22.shell 内置命令: declare 设置变量

image-20250719172059957

image-20250719172208122

image-20250719172401689

image-20250719172701272

image-20250719172737824

image-20250719173131377

image-20250719173158399

使用定义 索引数组的方式定义 关联数组,可以定义,但是 其中存在问题,不要使用

image-20250719173727953

image-20250719174011444

23.shell运算符:算术运算符

image-20250719182519330

image-20250719182709530

image-20250719182829739

image-20250719182911689

image-20250719183219810

image-20250719183245040

image-20250719183403739

24.shell运算符:比较运算符-整数比较

image-20250719183536090

image-20250719183642103

image-20250719183908908

image-20250719184005789

image-20250719184104852

image-20250719184259169

image-20250719184351439

image-20250719184423715

image-20250719184501620

25.shell 运算符:比较运算符-字符串比较

image-20250719184702112

image-20250719184735063

image-20250719185029786

image-20250719185402974

26.比较运算符-执行比较运算符方式区别

image-20250719185610507

image-20250719185743839

image-20250719185806734

image-20250719185923669

image-20250719190002481

image-20250719190037368

27.shell 运算符:布尔运算符

image-20250719204931922

image-20250719205206183

image-20250719205328349

28.shell运算符:逻辑运算符

image-20250719205423477

image-20250719205624624

image-20250719205647722

image-20250719210010778

29.shell 运算符: 文件测试运算符

image-20250719210057670

image-20250719210256600

image-20250719210335127

image-20250719210350363

image-20250719210437373

image-20250719210514238

image-20250719210802845

image-20250719211003127

image-20250719211120201

image-20250719211140427

image-20250719211314479

30.shell计算命令:expr 命令详解

image-20250719211424957

image-20250719211501756

image-20250719211552549

image-20250719211933373

image-20250719211949176

image-20250719212228487

image-20250719212627063

31.shell 计算命令: (()) 命令详解

image-20250719212726486

image-20250719212931933

image-20250719213014114

image-20250719213327098

image-20250719213404126

image-20250719213536409

32.shell计算命令:let 命令详解

image-20250719213647248

image-20250719213808326

image-20250719213847280

image-20250719214024088

image-20250719214043131

image-20250719214135442

33.shell 计算命令:$[]命令详解

image-20250719214240873

image-20250719214419082

image-20250719214744202

34.shell 计算命令: bc命令详解-互动式的数学运算

image-20250719214832010

image-20250719214943660

image-20250719215123407

image-20250719215143274

image-20250719215247826

image-20250719215339843

image-20250719215514491

image-20250719215822113

35.shell 计算命令:bc命令详解-shell 中非互动式的管道运算

image-20250719220143710

image-20250719220326240

image-20250719220525243

image-20250719220727715

image-20250719220824146

36.shell 计算命令:bc命令详解-shell非互动式的输入重定向运算符

image-20250719221212201

image-20250719221344807

image-20250719221459336

image-20250719221530107

image-20250719221755510

image-20250719221913996

37.流程控制:if else 语句

image-20250721211605660

image-20250721211633370

image-20250721211739645

image-20250721211808196

image-20250721212114362

image-20250721212147137

38.if条件判断句的退出状态

image-20250721212408356

image-20250721212543485

image-20250721212747505

​ 上图中的说明 中 1 和0 反了 ? shell 中大部分 0 代表成功, 1 代表失败

image-20250721212800469

image-20250721213137188

image-20250721213207033

39.shell 内置命令test

image-20250721213302475

image-20250721213509465

image-20250721213552965

image-20250721213635910

image-20250721213722005

image-20250721213821083

image-20250721213835732

image-20250721214002056

image-20250721214027598

image-20250721214124000

40.流程控制:case语句

image-20250721214245923

image-20250721214358575

image-20250721214514048

image-20250721214755002

image-20250721214816900

41.流程控制:while 语句

image-20250721214925831

image-20250721214939878

image-20250721220618082

image-20250721220644918

image-20250721220715631

image-20250721220834816

image-20250721220919555

image-20250721221147719

image-20250721221212898

42.流程控制:until语句

image-20250721221309868

image-20250721221345333

image-20250721221616246

image-20250721221642177

43.流程控制: for 语句

image-20250721221827402

image-20250721221841876

image-20250721222016888

image-20250721222111758

image-20250721222222994

image-20250721222238787

image-20250721222300508

image-20250721222415709

44.流程控制语句:select语句

image-20250721222505707

image-20250721222615673

image-20250721222803608

image-20250721222845643

image-20250721222902939

image-20250721223022618

image-20250721223047690

45.shell 函数: 系统函数

image-20250721223140409

image-20250721223530043

image-20250721223551442

image-20250721223722394

image-20250721223815009

46.shell函数:自定义函数-有返回值函数

image-20250721223940033

image-20250721224001520

image-20250721224042045

image-20250721224357959

image-20250721224432847

无参有返回值的函数

image-20250721224724571

image-20250721224743886

47.shell函数:有参函数

image-20250721224854469

image-20250721225139522

image-20250721225159592

image-20250721225223687

image-20250721225307392

image-20250721225421135

image-20250721225446460

48.shell 重定向:输出重定向

image-20250722211516664

image-20250722211631723

image-20250722211901962

image-20250722211952228

image-20250722212045110

image-20250722212208176

image-20250722212507560

image-20250722212534888

49.shell 重定向:输入重定向

image-20250722212742073

image-20250722213050549

50.shell 好用的工具:cut

image-20250722213203344

image-20250722213333420

image-20250722213940099

image-20250722214101243

image-20250722214309821

image-20250722214352663

image-20250722214453428

image-20250722214653353

51.shell 好用的工具:cut 切割指定单词-PID-IP地址

image-20250722220224795

image-20250722220303808

image-20250722220417955

image-20250722220503143

image-20250722220620747

image-20250722220716776

52.shell 好用的工具: sed-介绍与处理数据原理

image-20250722220850071

image-20250722221126341

image-20250722221201373

image-20250722221234033

image-20250722221324928

image-20250722221435189

53.shell 好用的工具: sed-向文件中添加数据

sed "3ahello" sed.txt   # 在第三行的后面添加hello, 在缓存中修改,将修改后的内容输出到屏幕, 不修改原文件

# 上面的命令加上 -i 参数, 修改原文件
sed -i "3ahello" sed.txt

image-20250722221729388

# 如下图, 在指定的行号后面添加数据
sed "3ihello" sed.txt   # 在第3 行的前面添加 hello  i-insert插入, 指定行的前面添加数据

image-20250722222121222

# 如下图, 在指定的内容前或后面添加内容

sed '/itheima/ihello' sed.txt   # 在 itheima 字符串 前面一行添加 hello  i-insert , 前面插入

sed '/itheima/ahello' sed.txt   # 在 itheima 字符串 后面一行添加 hello, append, 后面添加

image-20250722222551095

# 在最后一行前或者后添加 hello

sed "$ahello" sed.txt    # 在最后一行的后面添加数据hello, "$ahello" 其中 $ 代表最后一行, a 代表append 后面添加

sed "$ihello" sed.txt    # 在最后一行的前面添加数据hello, "$ihello" 其中 $ 代表最后一行, i 代表 insert 前面添加

image-20250722222942981

54.shell 好用的工具: sed-删除文件中的数据

image-20250722223614707

# 删除 文件中第二行的数据, 如下图
sed '2d' sed.txt   #  删除了 sed.txt 文件中的第二行数据

image-20250722223729161

image-20250722223819205

image-20250722223910043

image-20250722224000811

sed '1,3!d' sed.txt # 删除1 到 3 行以外的行, 如上图
# 删除文件中的最后一行 (如下图)
sed '$d' sed.txt

image-20250722224324587

image-20250722224345238

image-20250722224457195

image-20250722224603264

image-20250722224700595

image-20250722224723503

55.shell 好用的工具: sed-更改文件中的数据

image-20250722224912103

# 将文件中的第一行修改为 hello
sed '1chello' sed.txt  # 将 sed.txt 文件中的一行修改成 hello,  1 指第一行, c-change 修改

image-20250722225134626

image-20250722225210829

image-20250722225255162

image-20250722225402542

# sed 替换
sed 's/itheima/hello'  # 将每一行的第一个 itheima  替换成hello

sed 's/itheima/hello/g'  # 将所有的的 itheima 都替换成 hello,  在命令的后面加个 g, 全局替换

image-20250722225619691

image-20250722225715202

image-20250722225859835

image-20250722230026949

image-20250722230052063

image-20250722230156048

56.shell 好用的工具: sed-查询-管道过滤-多个sed 命令执行

image-20250722230723059

image-20250722230812244

image-20250722230937357

image-20250722231009177

image-20250722231132929

57.shell 好用的工具:sed-模式空间与暂存空间数据交换

image-20250722231326713

image-20250722231504901

image-20250722231744488

image-20250722232036370

image-20250722232133428

image-20250722232239417

image-20250722232344473

image-20250722232455283

image-20250722232512624

58.shell 好用的工具:awk介绍-默认分割-匹配查找-每行文件属性

image-20250723201341785

image-20250723201528541

image-20250723201544901

image-20250723201613660

image-20250723201646572

image-20250723201837599

image-20250723201929657

image-20250723201951932

image-20250723202134055

image-20250723202317421

image-20250723202451658

59.shell 好用的工具:awk 分隔符-根据行和列匹配数据打印

image-20250723202837839

image-20250723202942587

image-20250723203017145

image-20250723203041454

image-20250723203117913

image-20250723203215119

image-20250723203402544

60.shell 好用的工具:awk-添加开始与结束-循环-变量-运算符-总结文本处理四剑客

image-20250723203754751

image-20250723204009900

使用循环拼接分割后的字符串

image-20250723204040979

image-20250723204248941

image-20250723204418813

image-20250723204542786

image-20250723204751340

61.shell 好用的工具:sort

image-20250723204836612

image-20250723204910251

image-20250723204940461

image-20250723205009982

image-20250723205138516

image-20250723205221671

image-20250723205306750

image-20250723205338283

image-20250723205430723

image-20250723205540570

image-20250723205628591

62.面试题: 查空行

image-20250723205723771

63.面试题:求一列的和

image-20250723205844561

64.面试题:检查文件是否存在

image-20250723210034941

image-20250723210134316

65.面试题:数字排序

image-20250723210222448

image-20250723210321595

66.面试题:搜索指定目录下的文件内容

image-20250723210532484

67.面试题:批量生成文件名

image-20250723210910327

image-20250723211309976

68.面试题:批量改名

image-20250723211407025

image-20250723211621444

69.面试题:批量创建用户

image-20250723211716760

image-20250723212037286

image-20250723212056976

70.面试题:筛选单词

image-20250723212138472

71.面试题:单词及字符去重排序

image-20250723212336079

image-20250723212626431

image-20250723212714211

image-20250723212907188

72.面试题:扫描网络内存存活主机

image-20250723213006224

image-20250723213403720

image-20250723213435281

73.面试题:mysql 分库备份

image-20250723213553271

image-20250723214145006

image-20250723214206400

image-20250723214259231

74.面试题: mysql数据库分库分表备份

image-20250723214402647

image-20250723214724355

image-20250723214753238

image-20250723214830970

posted @ 2025-07-23 21:55  Ref-brief  阅读(12)  评论(5)    收藏  举报