linux 下shell脚本的编写

首先对脚本的编写进行一定的配置

脚本在编写时可以自己进行注释  以下通过修改vimr来简化操作

shell脚本
"map  <F4> ms:call  WESTOS()<cr>'s 打开后使用快捷键添加内容
autocmd BuFNewFile *.sh exec ":call WESTOS()"创建新文件自动添加
 func  WESTOS()
  call  append(0,"#######################")
  call  append(1,"#Author:         bobo".(" #"))
  call  append(2,"#Version:            ".(" #"))
  call  append(3,"#Mail:               ".(" #"))
  call  append(4,"#Date:      ".strftime("%Y-%m-%d").("#"))
  call  append(5,"#Description:        ".(" #"))
  call  append(6,"#                    ".(" #"))
  call  append(7,"#######################")
  call  append(8,"")
  call  append(9,"#!/bin/bash")
 endfunc



linux 下shell脚本的编写

linux 下shell脚本的编写


打包补丁的使用


yum  install   patch  -y  打补丁软件下载

137  vim   123
  138  vim  abc
  139  diff  123  abc 比较1  和a  1为目标
  140  diff   abc  123     a为目标
  141  diff  -u  abc  123  >  abc.paath  将1作为目标更改并保存补丁文件
  142  cat  abc.paath
  143  patch  -b  abc  abc.paath  对原文件进修修改
  144  ls
  145  cat  abc
  146  cat  abc.
  147  cat  abc.orig


linux 下shell脚本的编写

对目录进行比较

linux 下shell脚本的编写


编写查找ip的脚本

linux 下shell脚本的编写


ifconfig eth0|grep  'inet '|sed  's/.*inet//g'|sed  's/netmask.*//g'

这个为自己编写的脚本 使用sed来替换掉不需要看到的数据  不需要自己计算ip位于哪一部分


linux 下shell脚本的编写


linux 下shell脚本的编写


脚本2

ping指定ip时 对结果正误显示


linux 下shell脚本的编写


linux 下shell脚本的编写


对文件排序输出最大的文件名


sort

sort   -n  qqq 排序
  249  sort   -t :(分隔符)  -k指定列 2   qqq
  250  sort   -t :  -k 2  -u去idiao重复  qqq
  251  sort   -t :  -k 2  -r倒叙  qqq



linux 下shell脚本的编写


linux 下shell脚本的编写


对文件属性进行判定

linux 下shell脚本的编写


linux 下shell脚本的编写



显示文件的属性

linux 下shell脚本的编写


linux 下shell脚本的编写


linux 下shell脚本的编写


大小写转换

linux 下shell脚本的编写linux 下shell脚本的编写


判定数的大小处于区间

linux 下shell脚本的编写linux 下shell脚本的编写


脚本创建用户1

这个脚本对于文件中存在的字符进行查找 所以创建有些不存在的用户但有相同字符串存在文本中的时候  比如 user  会出现错误

这个之可以创建如123424513  jaklfj等等的用户

#!/bin/bash
cat  /etc/passwd|grep  $1  >/dev/null   &&  {
 echo  "user  exit"
   exit 1
}
useradd $1

echo  $2|passwd  $1 --stdin


使用如下脚本可以完整的创建用户



linux 下shell脚本的编写