脚本的编写规范:
1、声明解释器
#!/bin/bash
2、编写注释
#注释内容:脚本内容;作者介绍;脚本中个参数的含义
3、执行指令
[root@sur7 opt]# vim test01.sh
[root@sur7 opt]# cat test01.sh
#!/bin/bash
#这是一个测试脚本
echo nb
mkdir abc
脚本的执行方式
1、作为命令字;添加x权限
2、用解释器执行脚本:会同时开启解释器子进程
3、用source执行脚本(source直接用默认解释器:不开启解释器子进程)
[root@sur7 opt]# ls -l test01.sh ——> -rw-r–r--. 1 root root…test01.sh
[root@sur7 opt]# chmod +x test01.sh
[root@sur7 opt]# ls -l test01.sh ——> -rwxr-xr-x. 1 root root…test01.sh
[root@sur7 opt]# /opt/test01.sh ——> nb abc //使用绝对路径运行
[root@sur7 opt]# ./test01.sh ——> nb abc //使用相对路径运行
[root@sur7 opt]# bash test01.sh ——> nb abc
[root@sur7 opt]# sh test01.sh ——> nb abc
[root@sur7 opt]# source test01.sh——> nb abc
主进程------子进程
子进程在执行完程