1 / 10

Lab # 9

Lab # 9. Shell Script con. while loop. Syntax : while [ condition ] do command1 command2 command3 .. .... done. while loop. The case Statement. Syntax : case $variable-name in pattern1) command ... command;; pattern2) command

linus
Télécharger la présentation

Lab # 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab # 9 Shell Script con.

  2. while loop Syntax: while [ condition ] do command1 command2 command3 .. .... done

  3. while loop

  4. The case Statement Syntax: case $variable-name in pattern1) command ... command;; pattern2) command ... command;; patternN) command ... command;; *) command ... command;; esac

  5. Exercise(information of company employees ) • Write shell script to enter the information of company employees until the user enter 0 for employee’s id .The information is (Id , name , sex (M, F) , total hour worked in a month) • The script will list the information of all Males employees and females employees in two separate files named Males and Females and the total number of Males and total number of Females with average total hours worked for each with final result message ex. “The productive of males is better” or “The productive of females is better”.

  6. Input screen Enter employees information (id , name , sex, total hours) 1 mona F 200 2 manal F 180 3 Ahmed M 300 4 Nawal F 250 5 Yeosef M 240 6 Salman M 280 7 nada F 100 8 Marwan M 200 9 Rasha F 140 0 Males file The male’s information: Id name hours 3 Ahmed 300 5 Yeosef 240 6 Salman 280 8 Marwan 200 Total Males = 4 Avrage hours = 255 The productive of males is better Females file The male’s information: Id name hours 1 mona 200 2 Manal 180 4 Nawal 280 7 nada 100 9 Rasha 140 Total Females = 5 Avrage hours = 180 The productive of Females is the worst

  7. Solution(information of company employees ) total_males=0; males_hours=0 total_females=0; females_hours=0 echo “Enter employees information (id , name , sex, total hours)” read id name sex hours echo “The male’s information:”> Males echo –e “Id /t name /t hours “>> Males echo “The female’s information:”> females echo –e “Id /t name /t hours “>> females

  8. while [ $id –ne 0 ] do if [ $sex== “M” –o $sex==“m” ] ; then total_males=`expr$total_males + 1` males_hours=`expr$males_hours + $hours` echo “$id /t $name /t $hours” >> males else total_females=`expr$total_females + 1` females_hours=`expr$females_hours + $hours` echo “$id /t $name /t $hours”>>females fi read id name sex hours done

  9. echo “Total Males = $total_males”>> males Males_avg=`expr$males_hours / $total_males` echo “Average hours = $Males_avg“ >> males females_avg=`expr$females_hours / $total_females` “ echo “Total females = $total_females” >> females echo “Avrage hours =$females_avg“ >> females if [ $Males_avg –gt$ females_avg ] ; then echo “The productive of males is better” >> males echo “The productive of females is the worst ” >> females else echo “The productive of females is better” >> females echo “The productive of males is the worst ” >> males fi

More Related