![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Shell编程
Shell编程
weixing100200
这个作者很懒,什么都没留下…
展开
-
Vim查找替换及正则表达式的使用
代码】VIM。原创 2022-07-24 10:15:16 · 669 阅读 · 0 评论 -
?shell select
#!/bin/bashPS3="请选择要执行的程序. :"select program in 'netstat -antolp|grep "ESTABLISHED"' 'exit' 'date' 'pwd'do $programdone~原创 2022-01-23 19:15:33 · 399 阅读 · 0 评论 -
while循环语句
[root@i-3pedyvud ~]# cat quiz.sh#!/bin/bashecho "2007年12月19日选举的第17任大韩民国总统是谁?"read answerwhile [[ "$answer" != "李明博" ]]do echo "不是正确答案,请重新输入!" read answerdoneecho 正确答案. ::李明博[root@i-3pedyvud ~]# ...原创 2022-01-23 00:13:05 · 120 阅读 · 0 评论 -
for 命令
路径/root/123/* 下的文件添加X权限。[root@i-3pedyvud script]# cat permx1.sh#!/bin/bashfor file in /root/123/*do if [[ -f $file && ! -x $file ]] then chmod +x $file echo $file 向文件添加执行许可 fidone[root@i-3pedyvud script]#...原创 2022-01-21 10:53:30 · 576 阅读 · 0 评论 -
here文档和case
[root@i-3pedyvud ~]# cat apache_status1.sh #!/bin/bashecho "请选择启动或终止web服务器"cat <<- ENDIT 1、启动apache服务 2、终止apache服务 3、重启apache服务ENDITread choicecase "$choice" in1) STATUS="开始" systemctl start httpd ;;2) STATUS="终止" systemctl stop http.原创 2022-01-18 00:09:44 · 1344 阅读 · 0 评论 -
awk、strftime函数
[root@i-3pedyvud ~]# awk 'BEGIN{now=strftime("%D",systime());print now}'01/16/22[root@i-3pedyvud ~]# awk 'BEGIN{now=strftime("%T");print now}'13:57:42[root@i-3pedyvud ~]# awk 'BEGIN{now=strftime("%m/%d/%y");print now}'01/16/22[root@i-3pedyvud ~]# awk原创 2022-01-16 14:00:29 · 754 阅读 · 0 评论 -
if、else、else if、next
[root@i-3pedyvud ~]# cat awkdataTom 85Jane 91Mary 74[root@i-3pedyvud ~]# cat awkscript1 {if ($2 > 89 && $2 < 101) print $1,"的学分是:Grade A"else if ($2 > 79) print $1,"的学分是:Grade B"else if ($2 > 69) print $1 ,"的学分是:Grade C"el.原创 2022-01-15 17:21:22 · 185 阅读 · 0 评论 -
awk举例
按照第5列排序列出后,按照第4列为root,然后显示出目录文件[root@i-3pedyvud ~]# ls -l | sort -n -k5 | awk '$4 = "root"'| grep '^d'drwxr-xr-x 2 root root 21 1月 13 22:52 seddrwxr-xr-x 2 root root 33 1月 12 10:59 bindrwxr-xr-x 5 root root 43 1月 11 16:51 sharedrwxr-xr-x 5 root root.原创 2022-01-13 23:20:45 · 284 阅读 · 0 评论 -
echo hello 1>&2 |grep aaa echo hello 2>&1 |grep aaa
下面两条命令分别会有怎样的输出echo hello 1>&2 |grep aaaecho hello 2>&1 |grep aaa答:第一个输出hello,第二个无输出,解析如下1>&2 将正确输出重定向到标准错误2通道2>&1 将错误输出重定向到标准输出1通道echo hello 1>&2 后面跟了一个 |grep aaa| 是管道,意思就是将第一条指令的结果放到第二条指令中,管道命令右边只处理左...转载 2022-01-12 22:30:49 · 453 阅读 · 1 评论 -
shell function函数
[root@i-3pedyvud ~]# function myfunc { echo "当前目录为$PWD"; echo "当前目录的文件目录如下"; ls; echo “今天是$(date +%A).”; }[root@i-3pedyvud ~]# myfunc当前目录为/root当前目录的文件目录如下123 bin index.html.1 remove.txt12.原创 2022-01-12 20:43:06 · 203 阅读 · 0 评论 -
监控网络状态链接
#!/bin/bash#功能:监控网络连接状态脚本TCP_Total=$(ss -s | awk '$1=="TCP"{print $2}') #所有TCP连接个数UDP_Total=$(ss -s | awk '$1=="UDP"{print $2}') #所有UDP连接个数Unix_sockets_Total=$(ss -ax | awk 'BEGIN{count=0} {count++} END{print count}') #所有UNIX sockets连接个数TCP_Listen_.原创 2022-01-02 10:29:42 · 1037 阅读 · 0 评论