2021 华南农业大学Linux编程题

  1. 1、编写⼀段shell程序实现以下功能:
    根据键盘输⼊的学⽣成绩,显示相应的成绩等级, 其中
    60分以下为"Failed!“,
    60~69分为"Passed!”,
    70~79分为"Medium!“,
    80~89分为"Good!”,
    90~100为"Excellent!“。
    如果输⼊超过100的分数,则显示"error score”;
    实验eg,
    代码。。。
  2. 编写一个shell程序可以完成以下执行过程。
    [root@localhost ~]# ./main.sh
    Input a list of number:
    1 2 3 4 5 6
    the result is 21
    Input a list of number:
    1 1 1
    the result is 3
    Input a list of number:
    q
    [root@localhost ~]#
#! /bin/bash
while true
do 
        echo "input a list of number:"
        read num1

        result=0
    
        case $num1 in
        q|Q) 
                exit
                ;;  
                #这里可以直接if判断就好了,
        esac
        for val in $num1
        do    
                result=`expr $result + $val`
        done
        echo "the result is $result"
done            

实验部分

实验5:
在这里插入图片描述

eg3:

# ! /bin/bash

func(){
    echo "input a directory:"   
}
func
while read dir
do
    if [ $dir = "q" ];then
        exit    
    elif [ -e $dir -a -d $dir ];then
        for file in `ls $dir`
            do          
                if [ ! -e "$dir$file" ];then
                    dd="$dir/$file"     
                else            
                    dd="$dir$file"      
                fi              
                type=`ls -ld $dd | cut -c1`
                echo "${dd}_${type}"
            done        
    else 
        echo "$dir is not a directory"
    fi  
        echo -e 
    func
done

实验6
在这里插入图片描述

#! /bin/bash

echo "please, input a number:"

read num 

for((i=$num; i>=1; i--))
do
    for((j=$i; j>=1; j--));do
        echo -n  "$j "
    done
    echo
done
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
题目名称 linux实验-基本指令1 题目关键字 linux实验-基本指令1 题目录入时间 2013-4-1 22:36:02 题目内容 1、root帐号登录,查看/tmp目录,如果/tmp目录下没有子目录myshare,则建立该目录。 2、创建帐号testuser。 3、把myshare目录及其目录下的所有文件和子目录的拥有者该为testuser,工作组改为users。 4、切换至testuser帐号。进入/tmp/myshare目录,采用vim编辑器编写以上程序,程序名称为hello.sh: #!/bin/bash echo "app start" echo -e func (){ echo "hello world!" } func echo -e echo "app end" 5、保存hello.sh后,给予hello.sh拥有者可读、可写和可执行的权限,同组可读可执行,其他人可执行权限。 6、输入./hello.sh,观察程序输出的效果。 7、进入testuser的用户主目录,在这个目录下创建hello.sh的软链接,同时拷贝hello.sh到该目录下并改名为hello.sh.bak,要求拷贝时保留文件属性值。 8、退出testuser帐号,回到root帐号,从/开始查找后缀名为.conf的所有文件,把输出结果重定向到testuser帐号的主目录下的output.txt文件。 9、在上一步操作的.conf文件中找出文件容量最大的和最小那个,并把这两个文件的容量大小输出到output.txt文件中。 10、统计出系统中有多少个用户帐号,把数量输出到output.txt文件中。 11、把output.txt文件转换为windows记事本可正规打开的格式。 12、tar打包压缩testuser帐号主目录下的所有文件。 13、用U盘把上一步打包压缩文件拷贝到U盘上。 14、执行userdel -r testuser,执行rm -fr myshare 题目创建人 邝颖杰 题目注释 把打包压缩文件提交即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值