您的位置:首页 > 运维架构 > Shell

建立一个规范的shell脚本

2015-11-30 00:00 567 查看
脚本开头第一行指定解释器
#!/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]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: