zoukankan      html  css  js  c++  java
  • 4周作业

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

    [root@deng script]# cat test1.sh
    #!/bin/bash
    #
    #********************************************************************
    #Author: dengjun
    #QQ: 31532665
    #Date: 2020-06-27
    #FileName: test1.sh
    #URL:
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    Sum=0
    for i in `seq 1 100`;do
    if [ `expr $i % 3` -eq 0 ];then
    Sum=$(expr $i + $Sum)
    fi
    done
    echo $Sum


    2. 编写脚本,求 100 以内所有正奇数之和
    [root@deng script]# cat test2.sh
    #!/bin/bash
    #
    #********************************************************************
    #Author: dengjun
    #QQ: 31532665
    #Date: 2020-06-27
    #FileName: test2.sh
    #URL:
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    Sum=0
    for i in `seq 1 100`;do
    if [ $(($i%2)) == 1 ];then
    let Sum=$Sum+$i
    fi

    done
    echo $Sum

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


    #!/bin/bash
    #
    #********************************************************************
    #Author: dengjun
    #QQ: 31532665
    #Date: 2020-06-27
    #FileName: test3.sh
    #URL:
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    RandomNumber=$[RANDOM%11]

    while read -p "please put a number,1-10:" NU ; do
    if [ $NU -gt 10 ]; then
    echo"请输入1-10之内的数字"
    continue
    elif [ $NU -lt $RandomNumber ]; then
    echo "你输入的数字小了"
    elif [ $NU -gt $RandomNumber ]; then
    echo "你输入的数字大了"
    else
    echo "猜对了"
    break
    fi
    done

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

    [root@deng script]# cat test4.sh
    #!/bin/bash
    #
    #********************************************************************
    #Author: dengjun
    #QQ: 31532665
    #Date: 2020-06-27
    #FileName: test4.sh
    #URL:
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    formax () {
    if [ $1 -lt $2 ] ;then
    echo "$2"
    else
    echo "$1"
    fi
    }
    formax $1 $2

    5. 编写一个httpd安装脚本


    #!/bin/bash
    #
    #********************************************************************
    #Author: dengjun
    #QQ: 31532665
    #Date: 2020-06-27
    #FileName: test5.sh
    #URL:
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    yum install gcc apr-devel apr-util-devel autoconf pcre-devel openssl-devel redhat-rpm-config make tar bzip2 -y

    cd /usr/local/

    wget http://archive.apache.org/dist/httpd/httpd-2.4.43.tar.bz2

    tar -xjf httpd.2.4.43.tar.bz2

    cd httpd-2.4.43/

    ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl && make && make install


    echo "PATH=/apps/httpd/bin:$PATH" > /etc/profile.d/httpd.sh

    . /etc/profile.d/httpd.sh

    apachectl start

  • 相关阅读:
    Educational Codeforces Round 86 (Rated for Div. 2) D. Multiple Testcases
    Educational Codeforces Round 86 (Rated for Div. 2) C. Yet Another Counting Problem
    HDU
    HDU
    HDU
    HDU
    Good Bye 2019 C. Make Good (异或的使用)
    Educational Codeforces Round 78 (Rated for Div. 2) C. Berry Jam
    codeforces 909C. Python Indentation
    codeforces1054 C. Candies Distribution
  • 原文地址:https://www.cnblogs.com/blchangkong/p/13428400.html
Copyright © 2011-2022 走看看