脚本开头第一行指定解释器
#!/bin/bash或者#!/bin/sh
这行内容必须在脚本文件的第一行
其他位置就认为注释了
#!/bin/bash
# 作者
# 功能说明
# 版本
#=====================================
#代码注释说明
代码块1
#代码注释说明
代码块2
#=====================================
实例
#!/bin/bash
#
# author:eddy date:2015-11-30
# 打印100个数字
# version:1.0
#循环1-100
for i in {1..100}
do
#打印变量
echo $i
done
执行方式:
1.
chmod +x script.sh---->./script.sh
2.
/bin/bash script.sh
3.
source sctipt.sh或者 . sctipt.sh
注意source脚本里面改变的环境变量会影响到当前shell的环境
#!/bin/bash
#
#
cd /tmp
[root@eddy script]# sh test3.sh
[root@eddy script]# source test3.sh
[root@eddy tmp]#
转载于:https://my.oschina.net/eddylinux/blog/537610