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

  • 相关阅读:
    Restful api 返回值重复的问题
    fastDFS遇到的并发问题recv cmd: 0 is not correct, expect cmd: 100
    忽略警告@SuppressWarnings的用法
    Mysql 一些命令记录
    python 操作excel实现替换特定内容
    python 提取目录中特定类型的文件
    python使用tkinter无法获取输入框的值
    python使用tkinter无法给顶层窗体的输入框设定默认值
    游戏基础知识第一弹
    python 3.7.4 安装 opencv
  • 原文地址:https://www.cnblogs.com/blchangkong/p/13428400.html
Copyright © 2011-2022 走看看