• 第四周


    1. 计算 100 以内所有能被 3 整除的整数之和

     #!/bin/bash
    sum=0;
    for (( i=1;i<=100;i++ ));
    do
            [[ $[i%3] == 0 ]] && let sum+=$i ;
    done
    echo $sum

     

    2. 编写脚本,求 100 以内所有正奇数之和

    #!/bin/bash
    seq -s '+' {1,2,100} | xargs | bc
     

     

     

    3. 随机生成 10 以内的数字,实现猜字游戏,提示比较大或小,相等则退出

     #!/bin/bash
    num=$[RANDOM%10]
    count=0
    while :
    do
            read -p "一个1~10的随机数,你猜是多少:" guess
            [[ $guess =~ [[:alpha:]] ||  $guess =~ [[:punct:]] ]] && echo "无效输入
    " && exit
            let count++
            if [ $guess -gt $num ];then
                    echo "你猜大了"
                    exit
            elif [ $guess -lt $num ];then
                    echo "你猜小了"
                    exit
            else
                    echo "恭喜你猜对了"
                    exit
            fi
    done
        

     

    4. 编写函数,实现两个数字做为参数,返回最大值

    #!/bin/bash
    maxnum(){
    if [ $1 -gt $2 ];then
            echo "大的数字是$1"
    elif [ $1 -lt $2 ];then
            echo "大的数字是$2"    
    else
            echo "你输入的数字是相同的"
    fi
    }
    maxnum 12 23

     

     

    5. 编写一个httpd安装脚本

    #!/bin/bash
    rm -rf /usr/local/src/*
    dnf remove -y gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
    systemctl disabled --now firewalld.service
    sed -i.bak 's/^SELINUX=.*/SELINUX=disabled/'/etc/selinux/config
    setenforce 0
    dnf install -y gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
    wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.43.tar.bz2
    tar xvf httpd-2.4.43.tar.bz2 -C /usr/local/src
    cd /usr/local/src/httpd-2.4.43/
    ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
    make -j 4 && make install
    echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
    . /etc/profile.d/httpd.sh
    sed -i.bak 's/^User.*/User apache/;s/^Group.*/Group apache/;/^Server.*/a ServerName localhost:80'  /etc/httpd/httpd.conf
    userdel apache
    useradd -r -s /sbin/nologin -d /var/www/ -c Apache -u 48 apache
    apachectl start
     

    ------------恢复内容结束------------

  • 相关阅读:
    Java实现 蓝桥杯VIP 算法提高 进制转换
    数据备份服务商Rubrik获4000万美元B轮融资
    为QNetworkAccessManager添加超时提醒(自己记录一段时间里的下载字节数,用定时器去定期检测,从而判断是否超时)
    DIOCP3 DEMO的编译(去掉VCL前缀)
    Golang环境搭建,Notepad++配置Golang开发环境,Golang发送邮件
    川普当选对中国的好处在哪?(会注重实利,而不是虚的意识形态)
    带你走近AngularJS
    ASP.NET MVC学习之控制器篇扩展性
    微信语音识别及网页获取用户信息
    敏捷和自动化测试
  • 原文地址:https://www.cnblogs.com/xuziran88/p/13179173.html
Copyright © 2020-2023  润新知