微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

#文件增加内容
#!/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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐