求助高手十万火急
cwl04
|
1#
cwl04 发表于 2005-05-03 01:29
求助高手十万火急
我们老师布置了一个linux编程题给大家
里面有这样一个要求就是menu里面的 1. 添加系别信息 2. 添加学生信息 这两个文件要同时连接到add里面请问那位告诉能告诉我用何方法可以不发生冲突 本来的写法是这样的 mmmenu里面这样的 1) tput clear sh $add_file continue;; 2) tput clear sh $add_file continue;; adadd里面这样的 #ID:0 Name:Zhang qingpeng CNEC1 Number:38 #add_file #That is the Add New department and the student messages # # Define the file varibable department_file=department student_file=student # Display the add menu #adddepartment(){ while true #check the user enter number is XX format.if their type is wrong, enter again do echo -e "Department Number (XX):\c" read Department case $Department in "") echo -e "Department number not entered\n\n";; [0-9][0-9])break;; *)echo -e "Invalid Department number\n\n";; esac done #Enter Department name while true #check the user enter last name is only aphabets and spaces.if their type is wrong, enter again do echo -e "The department name:\c" read The case $The in "") echo -e "The department name not entered\n\n";; #*[!\ a-zA-Z]* that means the user can enter only aphabets and spaces. *[!\ a-zA-Z]*) echo -e "Last name can contain only aphabets and spaces\n\n";; *) break;; esac done #save the records to student file echo " Save" echo -e "$DepartmentThe:">>$department_file #when the user choose (y)es, add another records again echo -e "Add another?(y)es or (n)o:\c" read answer case "$answer" in [yY]|[Yy]es)tput clear;; *)exit;sh menu1;; esac done } #addstudent(){ #student_file=student while true #check the user enter number is SXXXXXXX format.if their type is wrong, enter again do echo -e "student ID (SXXXXXXX):\c" read student case $student in "") echo -e "studentt ID not entered\n\n";; [S][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )break;; *)echo -e "Invalid student ID\n\n";; esac done #Enter Name while true #check the user enter first name is only aphabets and spaces.if their type is wrong, enter again do echo -e " Name:\c" read Name case $Name in "") echo -e " Name not entered\n\n";; *[!\ a-zA-Z]*) echo -e " Name can contain only aphabets and spaces\n\n";; *) break;; esac done #Enter gender while true #check the user enter Middle Init Name is only aphabets and spaces.if their type is wrong, enter #again do echo -e "gender:\c" read gender case $gender in "") echo -e "gender Init not entered\n\n";; *[!\ a-zA-Z]*) echo -e "gender Init can contain only aphabets and spaces\n\n";; *) break;; esac done #Enter birthday while true #check the user enter birthday is xxxx-xx-xx format.if their type is wrong, enter again do echo -e "Birthday Number (XXXX-XX-XX):\c" read Birthday case $Birthday in "") echo -e "Birthday Number not entered\n\n";; [1-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] )break;; *)echo -e "Invalid birthday number ID\n\n";; esac done #Enter Department name while true #check the user enter last name is only aphabets and spaces.if their type is wrong, enter again do echo -e "The department name:\c" read The case $The in "") echo -e "The department name not entered\n\n";; #*[!\ a-zA-Z]* that means the user can enter only aphabets and spaces. *[!\ a-zA-Z]*) echo -e "Last name can contain only aphabets and spaces\n\n";; *) break;; esac done #Enter telephone number while true #check the user Enter Telephone number is 010-XXXXXXXX format.if their type is wrong, enter again do echo -e "Telephone Number (010-XXXXXXXX):\c" read Telephone case $Telephone in "") echo -e "Telephone Number not entered\n\n";; [0][1][0]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])break;; *)echo -e "Invalid Telephone Number\n\n";; esac done #save the records to student file echo " Save" echo -e "studentNamegenderBirthday:$Telephone:">>$student_file #when the user choose (y)es, add another records again echo -e "Add another?(y)es or (n)o:\c" read answer case "$answer" in [yY]|[Yy]es)tput clear;; *)exit;sh menu2;; esac done } #choose(){ # $choice = $choice $menu_file # if [ "$choice" = "6" ] ; then #addmenu1 #adddepartment #else #addmenu2 #addstudent #fi #} #choose 请请问大家如何解决这个问题的 |