shell脚本头文件优化
map ms:call WESTOS()'s
autocmd BufNewFile .sh,.script exec “:call AINI()” ##所有以.sh与.script结尾的文件都会自动写入函数AINI()中的内容
function AINI()
call append(0,"#################################")
call append(1,"# Author: #")
call append(2,"# Create_Time ".strftime("%Y-%m-%d")." #")
call append(3,"# Version: #")
call append(4,"# Mail: #")
call append(5,"# Description: #")
call append(6,"# #")
call append(7,"# #")
call append(8,"#################################")
call append(9,"")
call append(10,"#!/bin/bash")
endfunction
创建以.sh(.script)结尾的文件会直接写入AINI()函数中的内容(.script的文件不会有颜色显示,因为环境变量不同)
创建以.script结尾的文件
调试脚本
sh -x 脚本名 检查脚本的错误
脚本执行的方式
1. sh cheng 会开启新的shell环境来执行脚本中的命令
2. chmod +x /mnt/cheng
/mnt/cheng
3. source cheng
4. . cheng
编辑脚本cheng
sh 脚本名 执行脚本的方式(会开启新的shell执行命令)
sh cheng
幻数(指定脚本执行的环境在/bin/后接的环境(如/bin/bash)中执行)
chmod +x 脚本名
脚本路径
在/bin/bash中执行脚本
在/bin/tcsh中执行脚本
. 脚本
在当前环境中执行脚本
source 脚本
在当前环境中执行脚本
编写脚本清空日志
#!/bin/bash
x=`grep -A28 RULES /etc/rsyslog.conf | awk '!/^#/&&!/^$/{print $2}' | sed '/^:/d;s/-//g' `
for num in $x
do
> $num
cat $num
done