Linux 第四本书 第三单元--------shell脚本的基础知识

创建shell脚本

vim ~/.vimrc     ------用户级更改

 

 

  1 set nu ts=2 ai et sw=2
  2
  3 "map <F12> ms:call WESTOSSHELL()<cr>'s     ----设置快捷键<F12>开启脚本
  4 autocmd BufNewFile *.sh,.script call WESTOSSHELL()   ----自动开启脚本
  5
  6 func WESTOSSHELL()                                -------创建以下内容
  7   call append(0,"#################################")
  8   call append(1,"# Author:    ")                         ---作者
  9   call append(2,"# Createtime:  ".strftime("%Y-%m-%d"))  ---同步时间
 10   call append(3,"#################################")
 11  endfunc
 

 


=====================================================================                
执行shell脚本
在mnt下建立westos.sh

1.sh westos.sh    ---手动开启指定脚本

2.source  westos.sh  ----不开启新shell执行脚本

 

3.chmod +x westos.sh  ---开启脚本中指定的shell并使用此shell环境运行脚本
/mnt/westos.sh

对脚本调试

sh -x /mnt/westos.sh

 

显示结果:
+      ----命令
没有+  ----代表输出

习题:
clear_log.sh   此脚本能清空日志

 

  [ "$USER" != "root" ]&&{
   echo "please run $0 with root "
 exit
 }
 
  for I  in `grep -A $(sed -n $= /etc/rsyslog.conf) RULES /etc/rsyslog.c    onf | awk '!/^#|^$|:/{ print $2 }' | sed 's/-//g'`
   do
    > $I
 
   done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值