zoukankan      html  css  js  c++  java
  • 实验6 shell程序设计一(1)

    设计如下一个菜单驱动程序

    Use one of the following options:
    P:To display current directory
    S:To display the name of running file
    D:To display today's date and present time (要求显示为:2017-04-26 05:45:12) 
    L:To see the list of files in your present working directory
    W:To see who is logged in
    Q:To quit this program
    Enter your option and hit:
    菜单程序将根据用户输入的选择项给出相应信息。要求对用户的输入忽略大小写,对于无效选项的输入给出相应提示。要求使用case语句实现以上功能,输入相应的字母后应该执行相应的命令完成每项功能,如输入P或p,就执行pwd命令。
     
    #!/bin/bash
    
    function welcome()
    {
        echo -e "
    "
        echo "Use one of the following options:"
        echo "P: To display current derectory "
        echo "S: To display the name of running file"
        echo "D: To display today's date and present time"
        echo "L: To see the listing of files in your present working directory"
        echo "W: To see who is logged in"
        echo "Q: To quit this program"
        echo -n    "Enter your option and hit:"
        read a
        echo -e "
    "
    }
    welcome
    until [ $a = q -o $a = Q ];
    do
        case "$a" in
        p|P)
        pwd
        welcome
        ;;
        s|S)
        echo "The running file is $0"
        welcome
        ;;
        d|D)
        date
        welcome
        ;;
        l|L)
        ls -a
        welcome
        ;;
        w|W)
        who
        welcome
        ;;
        *)
        echo -n "Sorry,your option is wrong,please enter your option again"
        echo -e "
    "
        read a
        esac
    done
    echo "Thank you for your playing"
    exit 0
     
     
     
     
  • 相关阅读:
    如何进行有效沟通避免出现误会
    如何进行有效沟通
    怎样提高自己的团队合作能力
    javaScript简介
    css文本格式详解
    css简介及相关概念
    WebGL10---3D模型的加载与使用
    Canvas绘图与动画详解
    Canvas绘制时钟
    WebGL9----将canvas作为纹理,将动画作为纹理(2)
  • 原文地址:https://www.cnblogs.com/double891/p/9005593.html
Copyright © 2011-2022 走看看