shell脚本的基础知识
什么是shell
脚本中命令的解释器
shell脚本的意义
- 记录命令执行的过程和执行逻辑,以便以后重复执行
- 脚本可以批量处理主机
- 脚本可以定时处理主机
如何创建shell脚本
- #!/bin/bash ##幻数
- 通过编辑/etc/vimrc 文件实现vim自动添加脚本首部
如何执行shell脚本
-
手动在环境中开启指定解释器
sh script.sh -
直接在当前环境中运行shell中的指令不开启新的shell
source script.sh
. script.sh -
开启脚本中指定的shell并使用此shell环境运行脚本中的指令
chmod +x script.sh
/xxx/xxx/script.sh
./script.sh
如何对脚本进行调试
sh -x /mnt/westos.sh
+ | 运行指令 |
---|---|
不带+ | 命令运行的输出 |