linux课后作业1

本实验6第一题:菜单驱动程序.

随便进到某个目录,vim driver.sh

把代码写进去。

#!/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
       

#!/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 " "}welcomeuntil [ $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        esacdoneecho "Thank you for your playing"exit 0       

原文地址:https://www.cnblogs.com/double891/p/8974774.html