call append(2,"# Version: ")
call append(3,"# Create_Time: ".strftime("%Y/%m/%d"))
call append(4,"# Mail: [email protected]")
call append(5,"# Info: ")
call append(6,"# ")
call append(7,"################################################")
call append(8,"")
call append(9,"#!/bin/bash")
endfunc
效果如下:

#### **四、如何执行shell脚本**
这里用 sleep 1000 作为实验脚本
1).手动在环境中开启指定解释器
sh script.sh

2).直接在当前环境中运行shell中的指令不开启新的shell
source westos.sh
. westos.sh


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


五、 如何对脚本进行调试
sh -x /mnt/westos.sh

脚本练习
1
ip_show.sh 网卡 显示当前的主机名称
####################################
#Author sun
#Create_Time: 2020/12/10
####################################
#!/bin/bash
[ -z $1 ] && {
echo -e “\033[31mError:Please input interface following script\033[0m”
exit
}
ifconfig KaTeX parse error: Expected 'EOF', got '&' at position 3: 1 &̲> /dev/null && …(ifconfig $1 | awk '/inet>/{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') [ -z "IP" ] && {
echo “$1 is not have ipaddress”
}||{
echo $IP
}
}||{
echo -e “\033[31mError: $1 is not exist !!\033[0m”
exit
}
**验证:**

2
host_messages.sh 显示当前主机的名称,ip登陆当前主机的用户
hostname: xxxxx
ipaddress: xxxx.xxxx.xxx.xxx
username: root
####################################
#Author sun
#Create_Time: 2020/12/10
####################################
#!/bin/bash
echo hostname : “ ( h o s t n a m e ) " e c h o i p a d d r e s s : " (hostname)" echo ipaddress : " (hostname)"echoipaddress:"(ifconfig enp1s0 | awk '/inet>/{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲')" echo usern…USER”
**验证:**

clear_log.sh 执行次脚本后可以清空日志
vim /etc/rsyslog.conf 在配置文件中查看所有日志存放的位置


####################################
#Author sun
#Create_Time: 2020/12/10
####################################
#!/bin/bash
[ KaTeX parse error: Undefined control sequence: \0 at position 33: …| { echo -e "\̲0̲33[31mPlease ch…(sed -ne ‘s/-//g’ -e ‘//var/log/p’ /etc/rsyslog.conf | awk ‘{print $2}’)
for i in $LOG
do
$i && {
echo -e “\033[32m $i cleared\033[0m”
}
done
**验证:**

最全的Linux教程,Linux从入门到精通
======================
1. **linux从入门到精通(第2版)**
2. **Linux系统移植**
3. **Linux驱动开发入门与实战**
4. **LINUX 系统移植 第2版**
5. **Linux开源网络全栈详解 从DPDK到OpenFlow**

第一份《Linux从入门到精通》466页
====================
内容简介
====
本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。

**本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**
> 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论