一、编写两个简单的shell脚本 (shell脚本需要以.sh扩展名)
[root@shellhost ~]# cd /scripts/day1/
[root@shellhost day1]# vim test1.sh
vim test2.sh
二、执行脚本
方法一:
bash test1.sh
或者
sh test1.sh
方法二:
给脚本添加执行权限:chmod +x test1.sh再如下执行脚本
./test1.sh
方法三:
source test1.sh
或者
. test1.sh
方法四:
sh < test1.sh
或者
cat test1.sh | sh
#区别
三、快速生成脚本开头的版本版权注释信息
[root@localhost day1]# vim ~/.vimrc
autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"##############################################################")
call setline(3, "# File Name: ".expand("%"))
call setline(4, "# Version: V1.0")
call setline(5, "# Author: xiaohong")
call setline(6, "# Email: xiaohong@163.com")
call setline(7, "# Organization: http://www.cnblogs.com/xiaohong/")
call setline(8, "# Created Time : ".strftime("%F %T"))
call setline(9, "# Description:")
call setline(10,"##############################################################")
call setline(11, "")
endif
endfunc
此时创建一个以 .sh结尾的文件自动会生成版本注释信息
[root@localhost day1]# vim test.sh