溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

shell腳本:簡(jiǎn)單的分?jǐn)?shù)記錄系統(tǒng)

發(fā)布時(shí)間:2020-07-23 02:36:43 來源:網(wǎng)絡(luò) 閱讀:761 作者:q381989042 欄目:開發(fā)技術(shù)

直接上代碼:

#mcore.sh
#!bin/bash

function colour()
{
	case $1 in
		black_white) 
			echo -e "\033[40;37m"
			;;
		black_green)
			echo -e "\033[40;32m"
			;;
		black_cyan)
			echo -e "\033[40;36m"
			;;
		red_yellow)
			echo -e "\033[41;33m"
			;;	
		yellow_blue)
			echo -e "\033[43;34m"
			;;
	esac		
}

function search()
{
	colour black_white
	clear
	echo -e "please enter name >>>\c"
	read NAME
	if [ ! -f ./record ]; then
		echo "you must have some scores before you can search"
		sleep 2
		clear
		return 
	fi

	if [ -z "$NAME" ]; then
		echo "you didn t enter a name!"
		echo -e "please enter name >>>\c"
		read NAME
	fi

	grep -i "$NAME" ./record 2> /dev/null

	case "$?" in
		1)	echo "Name not in record"
			;;
		2) echo "you didin t enter a name to search"
			search;;
	esac
}

function add()
{
	clear
	echo "enter name and score of a record"
	echo -e "\c"

	if [ ! -f ./record ];then
		touch record
	fi
	read NEWNAME
	echo "$NEWNAME" >./record

	sort -o ./record ./record
}

function delete()
{
	clear
	echo -m "please enter name >>\c"
	read NAME
	if [ ! -f ./record ];then
		echo "this name is not in record"
	else
		cp record record.bak
		rm -f record
		grep -v "$NAME" ./record.bak > record
		rm -f record.bak
	fi
}

function display()
{
	colour black_white
	more ./record
}

function edit()
{
	vi ./record
}

function help()
{
	clear
	colour black_cyan
	echo "this is a student s record program by lunix shell language"
}

function quit()
{
	clear
	colour black_white
	exit
}

clear

while true
do 
	colour red_yellow
	echo "****************************************"
	echo "*STUDENT S RECORD MENU                 *"
	echo "****************************************"
	colour yellow_blue
	echo "****************************************"
	echo "*1:search a record                     *"
	echo "*2:add a record                        *"
	echo "*3:delete a recore                     *"
	echo "*4:dispaly all records                 *"
	echo "*5:edit record witm vi                 *"
	echo "*H:help screen                         *"
	echo "*Q:exit program                        *"
	echo "****************************************"
	colour black_green
	echo -e -n "\tplease enter you choice 1--5,H,Q:\c"
	read CHOICE

	case $CHOICE in
		1) search;;
		2) add; clear;;
		3) delete; clear;;
		4) display;;
		5) edit; clear;;
		H | h) help;;
		Q | q) quit;;
		*)	echo "invalid choice"; 
		sleep 2;
		clear;;
	esac
done

運(yùn)行結(jié)果:

shell腳本:簡(jiǎn)單的分?jǐn)?shù)記錄系統(tǒng)

shell腳本:簡(jiǎn)單的分?jǐn)?shù)記錄系統(tǒng)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI