shell基本介绍
1.什么是shell
在Linux内核与用户之间的解释器程序
通常指 /bin/bash
负责向内核翻译及传达用户/程序指令
相当于操作系统的“外壳”
[root@svr7 ~]# cat /etc/shells #查看所有解释器
shell脚本
- 声明解释器
#!/bin/bash
- 编写注释
#编写脚本功能、作者信息、变量作用等内容
- 执行指令
脚本的的执行方式
#!/bin/bash
mkdir abc
cd abc
echo abc
1.添加x权限,使用绝对路径或者相对路径的方式执行 (标准)
]# chmod u+x /opt/test01.sh#添加x权限
]# /opt/test01.sh #执行脚本
用户(root)---bash---bash---echoabc #执行脚本的过程
2.使用解释执行器的方式执行脚本,可以不加x权限 (常用)
]# bash /opt/test01.sh #执行脚本
用户(root)---bash---bash---echoabc #执行脚本的过程
3.使用source命令执行脚本,可以不用加x权限
]# source /opt/test01.sh #执行脚本
用户(root)---bash---echoabc #执行脚本的过程
部署yum的shell脚本
]# vim /opt/test03.sh
#!/bin/bash
#部署yum仓库
mkdir /mytest
mount /dev/cdrom /mytest
rm -rf /etc/yum.repos.d/*.repo echo
"[abc]