目录
shell概述
- 弱类型编程语言
- 计算机操作系统只能识别0 1,我们通过GUI或CLI(图形化界面/命令行)的方式间接操作操作系统
- GUI和CLI在用户和操作系统之间,相当于桥梁、中介的作用,结构上看,GUI和CLI(壳)保护操作系统(核)
- GUI和CLI就是通过shell实现的
执行shell脚本,就好比在命令行输入一些dos命令
shell分类
- GUI样式的shell
- CLI样式的shell
shell编程专指:linux下的shell编程(linux:.sh 文件
windows: .bat 文件)
规范
首行:#! /bin/bash # 声明文件的解释器,#! /bin/sh,sh和bash都是shell的解释器
shell脚本的运行方式
- sh / bash 脚本
- 绝对路径 / 相对路径 # 注意权限:chmod 777 1.sh
- source 脚本
注释
单行注释(常用):# 注释文本
多行注释:
:<<自定义标记
……
自定义标记
变量
增:
等号左右两边不可以有空格;
值可不加引号、单引、双引均可,中间有空格时需加单或双引号
[root@localhost shell]# name=星魂
[root@localhost shell]# echo ${name}
星魂
[root@localhost shell]# name='hello 星魂'
[root@localhost shell]# echo ${name}
hello 星魂
[root@localhost shell]# name="hello 星魂"
[root@localhost shell]# echo ${name}
hello 星魂
[root@localhost shell]#删:
[root@localhost shell]# unset name1
改:
和增一样
查:
[root@localhost shell]# name=ww
[root@localhost shell]# echo $name
ww
[root@localhost shell]# echo ${name}
ww
[root@localhost shell]# echo '${name}'
${name}
[root@localhost shell]#