1.Shell概述
(1)Shell概念
![](https://ooo.0o0.ooo/2016/05/03/57286a3d3afe7.png)
![](https://ooo.0o0.ooo/2016/05/03/57286b60eb3b3.png)
(2)Shell分类
![](https://ooo.0o0.ooo/2016/05/03/57286cf81322f.png)
![](https://ooo.0o0.ooo/2016/05/03/57286d156fc88.png)
![](https://ooo.0o0.ooo/2016/05/03/57286d39d670b.png)
![](https://ooo.0o0.ooo/2016/05/03/57286df8e3743.png)
![](https://ooo.0o0.ooo/2016/05/03/57286e274d2b5.png)
![](https://ooo.0o0.ooo/2016/05/03/57286ec4c5710.png)
举例:
![](https://ooo.0o0.ooo/2016/05/03/57286f2b68702.png)
2.脚本执行方式
![](https://ooo.0o0.ooo/2016/05/03/572870ee9692e.png)
![](https://ooo.0o0.ooo/2016/05/03/57287111788bc.png)
举例1:
![](https://ooo.0o0.ooo/2016/05/03/572871c10dd70.png)
举例2:
![](https://ooo.0o0.ooo/2016/05/03/572871fb57a24.png)
![](https://ooo.0o0.ooo/2016/05/03/57287318b2738.png)
举例:
![](https://ooo.0o0.ooo/2016/05/03/5728733290e3c.png)
![](https://ooo.0o0.ooo/2016/05/03/572873482844d.png)
举例1:
![](https://ooo.0o0.ooo/2016/05/03/57287420d7d7a.png)
举例2:
![](https://ooo.0o0.ooo/2016/05/03/5728748c025da.png)
Linux本机(纯字符界面)不支持中文,远程工具可以(UTF-8),图形界面也可以支持。
![](https://ooo.0o0.ooo/2016/05/03/57287525b4ce3.png)
举例:
![](https://ooo.0o0.ooo/2016/05/03/57287635ed5d8.png)
![](https://ooo.0o0.ooo/2016/05/03/572876d73946f.png)
Shell中"#"号代表注释,但是"#!/bin/bash"不是注释,它是Shell中的默认脚本,必须写。
使用vi XX.sh
进入后,按"o
"进入编辑模式,写完脚本后,按"ESC
"键加":wq
"保存退出。
![](https://ooo.0o0.ooo/2016/05/03/572966b54b221.png)
3.Bash的基本功能
(1)命令别名与快捷键
什么是别名
- 命令别名==人的小名
![](https://ooo.0o0.ooo/2016/05/03/5729692a9e6f7.png)
![](https://ooo.0o0.ooo/2016/05/03/57296c19840e8.png)
unalisa只是临时删除
![](https://ooo.0o0.ooo/2016/05/03/57296dc537988.png)
![](https://ooo.0o0.ooo/2016/05/03/57296f8247c87.png)
(2)历史命令
![](https://ooo.0o0.ooo/2016/05/03/5729708b86a8f.png)
![](https://ooo.0o0.ooo/2016/05/03/57297348591fb.png)
![](https://ooo.0o0.ooo/2016/05/04/572992ced761c.png)
![](https://ooo.0o0.ooo/2016/05/04/572994235df9c.png)
(3)输出重定向
![](https://ooo.0o0.ooo/2016/05/04/5729966a72223.png)
![](https://ooo.0o0.ooo/2016/05/04/5729986cabdc8.png)
![](https://ooo.0o0.ooo/2016/05/04/57299caa919ff.png)
![](https://ooo.0o0.ooo/2016/05/04/57299f2763370.png)
输入wc命令后,输入内容,按"Ctrl+d"会显示统计行列数和字符数。
![](https://ooo.0o0.ooo/2016/05/04/57299ffd6e102.png)
(4)多命令顺序执行
![](https://ooo.0o0.ooo/2016/05/04/5729a1f7bf7c8.png)
"&&"和"||"不能交换位置,一定要先写逻辑与"&&",在写逻辑或"||"。
![](https://ooo.0o0.ooo/2016/05/04/5729b082a4f44.png)
![](https://ooo.0o0.ooo/2016/05/04/5729b0ff195ce.png)
![](https://ooo.0o0.ooo/2016/05/04/5729b13ae3953.png)
命令1报错,命令2不会执行。管道符的要求更加严格。
![](https://ooo.0o0.ooo/2016/05/04/5729b35b7cefa.png)
(5)Shell中的特殊符号
![](https://ooo.0o0.ooo/2016/05/04/5729b40220beb.png)
通配符通常用来匹配文件名或者目录名称。
![](https://ooo.0o0.ooo/2016/05/04/5729b7de89963.png)
![](https://ooo.0o0.ooo/2016/05/04/5729b81a73d0d.png)
![](https://ooo.0o0.ooo/2016/05/04/5729ba6d6230b.png)