加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

SHELL训练营--day23_shell练习56-60

发布时间:2020-12-15 23:02:32 所属栏目:安全 来源:网络整理
导读:#文件增加内容 #!/bin/bash n=0 cat 1.txt |while read line do n=[$n+1] if [ $n -eq 5 ] then echo $line echo -e "#This is a test file.n#Test insert line into this file." else echo $line fi done #备份/etc目录 #!/bin/bash d1=`date +%d` d2=`dat
#文件增加内容 #!/bin/bash n=0 cat 1.txt |while read line do n=[$n+1] if [ $n -eq 5 ] then echo $line echo -e "#This is a test file.n#Test insert line into this file." else echo $line fi done #备份/etc目录 #!/bin/bash d1=`date +%d` d2=`date +%y%m%d` if [ $d1 == "01" ] then cd /etc/ tar czf /root/bak/$d2_etc.tar.gz ./ fi #找出重复的单词 #!/bin/bash for w in `sed ‘s/[^a-zA-Z]/ /g‘ $1` do echo $w done|sort|uniq -c |sort -nr |head #比较两数大小 #!/bin/bash if [ $# -ne 2 ] then echo "请提供两个参数。" exit fi if_number() { if echo $1|grep -q ‘^-‘ then nu=`echo $1|sed ‘s/^-//‘` else nu=$1 fi n=`echo $nu|sed ‘s/[0-9.]//g‘` if [ -n "$n" ] then echo "$1不是合法数字。" exit fi if echo $nu|grep -q ‘^.‘ then echo "$1不是合法数字。" exit fi } if_number $1 if_number $2 n1=`echo "$1>$2"|bc` n2=`echo "$1-$2"|bc` if [ $n1 -eq 1 ] then echo "$1 > $2" elif [ $2 -eq 0 ] then echo "$1 = $2" else echo "$1 < $2" fi

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读