Shell Scripts辅导、Unix / Linux讲解、c/c++辅导、讲解C/C++编程

- 首页 >> C/C++编程


Shell Scripts Page 1

Shell Scripts LABORATORY TWO

OBJECTIVES

1. Processes in Unix / Linux

2. Common Shell Commands

3. Basic Shell Script Programming

4. File Transfer Protocol

5. Web Pages Publishing

Working from Home

You would often have a need to work at home and want to have access to Linux and Unix (those running

Mac OS/X will have your access to a Unix already – Mac OS/X is built on top of a variant of Unix).

When you are at home, you have to use ssh or putty to connect to machines in Department of

Computing. The departmental machines are protected against arbitrary direct access from outside PolyU.

That will provide better protection against hackers. To connect to a machine in the department, say,

apollo, you need to connect first to the gateway machine, called csdoor. Once you are in csdoor, you

could connect to other machines in the department.

To connect from home, execute ssh 12345678d@csdoor.comp.polyu.edu.hk

Type your password and answer yes when you are prompted about the RSA key fingerprint

After logging in to csdoor, type the name of the machine to connect to, for example, apollo

You now enter your password to login the machine

If you do not have ssh installed on your PC, you could download, install and then execute putty from

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html followed

by typing csdoor.comp.polyu.edu.hk as hostname. Select port 22 and connection type SSH.

After you have logged in to csdoor, you could also type load to check for the loading of the list of

available machines before you decide to select a machine with fewer users to connect to. There are

currently two accessible Linux machines, namely, apollo and apollo2. Mac machines are running Unix.

Processes in Unix / Linux

In Unix / Linux, one or more processes will be created when executing programs using the shell. The set

of processes existing in the system could be viewed by means of the ps command. For example, you

could type the command ps -elf to see a list of processes. Each process is identified by a process id

or simply pid. Most processes in the system would be in “S” state (suspended) under the the “S” or

“STAT” column. The process executing ps is itself in “R” state (running). There could be several

processes in this “R” state, when there are multiple CPUs with the machine, like apollo2. You may

monitor the list of processes currently executing in the machine, by the command top. You should be

seeing many more processes on apollo2, inclusive of other students’ processes.

If you find that a particular process may have fallen into an infinite loop, you could attempt to terminate

that process by killing it. You will use the kill command, by supplying the process ID, which can be

seen when you type the command ps -elf for the list of processes, e.g., to terminate process 12345,

type kill 12345 and if you still cannot kill it, use the stronger option kill -9 12345

The invocation of a program is called a job or a task in Unix / Linux. A job normally creates one

process, but could also create multiple processes to complete the mission. For example, the commonly

used pipe or “|” operator in shell generates multiple processes. For example, type ls –l | more and

Shell Scripts Page 2

you can use ps to check that there are two processes created, one for ls -l and the other for more.

The ls and more commands are executed together for a job. In this case, you have to use another shell

(e.g., use another ssh client) to check because you could not type the ps command when the ls and

more commands are still being executed. We could try a sequence of commands for a job like ps;

pwd; cal 2019. Processes belonging to the same job form a process group.

You could use multiple ssh clients when you are using the computers in the laboratory so that each

program you want to execute can be run on different windows (ssh or putty sessions). However, if

you are connecting from home, you may have only one terminal or only one connection to Linux. Then

could we execute multiple jobs together? Luckily, the answer is yes, and it works with C-shell (csh)

and Bourne-again shell (bash). The default shell on apollo running a variant of Linux called CentOS

and on most Mac machines running OS/X is bash (version 4.2 for apollo and version 3.2 for Mac).

At any moment, there is only one process group derived from one job that is connected to the keyboard

for input, but there could be multiple jobs not connected to the keyboard running at the same time. We

say that these multiple jobs, except for the one currently connected to the keyboard, are being run in

background. The one connected to the keyboard is running in foreground. All these multiple background

processes could still produce outputs to the screen, and all the outputs from all the jobs will be

intermixed together. To put a job to background, use the “&” operator when you run the job.

Alternatively, to put an already running job to the background, you will first type “<Ctrl>-Z” to stop

the job and then type bg to put it to the background. To put a specific background job to the foreground,

use fg command with the job number.

Try running the long printing program lab2A.c three times with different inputs simultaneously and you

could see an intermixed output. Type ps –lf to see your processes (perhaps using another window).

cc lab2A.c –o lab2A

./lab2A first 50 &

./lab2A second 60 &

./lab2A third 40 &

Repeat the above execution of the three processes on three different windows (terminals). Now we do

not need to use “&” operator. All processes can receive inputs from the keyboard and produce outputs to

the appropriate windows. Ability to switch jobs between background and foreground via bg and fg will

be useful when you do not have the luxury of multiple windows but have to do multiple tasks, for

example, when you are connecting from remote PC at home via one connection.

Do you find that the lines are intermixed together to make it very difficult to type in the new command

when a single window is used? To relieve the problem, you could create a script to contain all the

commands. For example, you could create a (script) file called allLab2 to contain the following lines:

./lab2A first 50 &

./lab2A second 60 &

./lab2A third 40 &

You should normally type chmod 700 allLab2 to make the script file allLab2 executable. You

can then execute the jobs by typing allLab2. The effect is just like typing the three lines on the

keyboard by yourself, like a batch file.

Here is a list of common commands used with processes.

Command Usage Description

ps ps -ef Show the processes in the computer

kill kill %2

kill 4321

kill -9 4321

Terminate a background job

Terminate a process

Terminate a process more forcefully

bg bg Move a stopped foreground job to background

fg fg %2 Move background job number 2 to foreground

jobs jobs Show the list of background jobs

Shell Scripts Page 3

time time a.out Show the total execution time of a program and its share of CPU time

uptime uptime Show the current workload of the computer, e.g., number of users

top top Show the CPU and resource utilization of the computer with a list of

active processes

More Shell Commands and Variables

Sometimes, users will try to customize their Linux system to look like whatever system they are familiar

with, by changing the meaning of commands or create new commands. Recall that this is achieved via

the use of alias, e.g., make ls behave like what you like by setting an alias for the command, alias

ls=’ls –l’, or use the more familiar command dir via alias dir=ls. If you want to define

many aliases at the same time, you may put them into a “batch” file and execute it (like .bat file in

MS-DOS). Then you do not need to type in the alias commands every time you login the system. Just

place all your aliases into a file, e.g., myalias. You can then execute this file containing useful aliases

by typing source myalias. You are encouraged to create your own alias file to customize your

Linux. Note that you can also execute allLab2 above via the source command, i.e., source

allLab2. The file does not need to be changed to executable via chmod if source command is used.

In Unix / Linux, you could know more about the hardware platform that you are using with the uname

command. Try out uname –a on apollo2 and/or another machine (perhaps even a Mac). You can know

the full name of your machine by hostname. Recall that pwd returns the current path where you are

working. Connecting these together with the whoami and pwd commands, you can change the

command prompt easily. In bash, the command prompt is defined within the variable PS1. Type echo

$PS1 and see the information about the format.

echo $PS1

On apollo, you would see something like \u \h:${PWD}$. Here \u means the user name (which can

be retrieved by whoami), \h means the machine name (a full version can be retrieved by hostname),

${PWD} evaluates the variable PWD in the current shell. This variable contains the current (present)

working directory in full (which can be retrieved by the command pwd). On a Mac, you would see

\h:\W \u\$, where \W means the current directory.

You may want to make the prompt like

Mickey@apollo2:

you could type

export PS1=”Mickey@\h: ”

To make the prompt like

(/home/12345678d) 12345678dyou

could type

export PS1=”($PWD) $(whoami)- ”

To make the prompt like

Linux@apollo2 [30]:

where 30 is the current command number, you could type

export PS1=”$(uname)@\h [\!]:”

Many Unix / Linux functions are defined based on system variables, which are called shell variables.

Here, PS1 is a shell variable that directs Linux shell to display its content as the (primary) prompt. There

are two types of shell variables, namely, global variables and local variables in bash and csh. A global

variable is called an environment variable. An environment variable can be created via the export

command in bash, converting a local variable into a global variable. Once created, the environment

variable can be accessed and modified (using =) in the regular manner. You can also remove the

environment variable by the unexport command. You would need to use the command setenv

Shell Scripts Page 4

instead of set to modify an environment variable in csh. The concept of environment variables is

useful, since their contents can be accessed by a C or Java program to serve their purpose, e.g. knowing

who is running the program. Recall that we have made use of a special variable called PATH in Lab 1,

by executing export PATH=”$PATH:.”. This command has the effect of inserting the current

directory “.” at the end of the current value stored in the variable PATH. Unix / Linux will then treat this

as the search path for any command to be executed.

When you type ls -l, you will see the permission mode for your files, the first one indicates whether it

is a directory (where d means a directory and - means a file, and it is also used to indicate special

system-related privileges), the first part for yourself, the second part for users in the same group, and the

third part for all other users. For each part, the privileges refer to read, write and execute respectively.

Note that the rest of this paragraph is valid for standard Unix / Linux systems in many other institutes

and for your personal web page (/webhome/12345678d/public_html). This standard access

permission arrangement is also valid under /tmp, but it is more dangerous to try at /tmp, since

everybody logging onto the same machine (apollo or apollo2) will be accessing and sharing the SAME

/tmp. You might ignore this part if you just use the departmental file system, but it is still useful to

learn about the general Unix / Linux file system settings. In Unix / Linux systems, you better change the

permission mode for your home directory from the default drwx--x--x (everyone can “execute”

your directory, i.e., can access its content) or even worse drwxr-xr-x (everyone can see the files and

access the content) to drwx------ (no one else could access), with chmod 700

/webhome/12345678d. Here the parameter for chmod is expressed in Octal (base 8), one octet for

each part, so that 7 means rwx and 5 means r-x.

If you use the departmental file system, you will almost always see drwx------ for any directory and

-rwx------ for any file. Only the write privilege can be set currently. Thus, performing chmod 644

or chmod 600 or chmod 777 will not have created change. If you perform chmod 000, you could

get –r-x------ for a file. Changes in local desktop files would not be carried back to the file system.

The First Shell Script

Try to run the following first shell script program in bash, call it firstscript.sh. Just type the

script name to execute it, after setting via chmod 700. Note that you may need to make some changes

to the program text before it can be executed, if you merely copy it from the pdf file. Watch out for

difference in quotation symbols and for ^M characters when you make the copy, before you try to run it.

This is one of the major reasons that a seemingly correct shell script program cannot run properly on the

actual machine. You can use the command dos2unix available on most Unix and Linux systems to

perform removal of those ^M characters for file firstscript.sh:

dos2unix firstscript.sh

The dos2unix command is not available in Mac OS/X, but you can still do the same trick using the

following approach, by creating a new file called firstscript2.sh:

tr –d ’\r’ < firstscript.sh > firstscript2.sh

#!/bin/bash

echo Hello $USER, time is $(date)

# $(date) allows the COMMAND/PROGRAM date to be executed and replacing the output

echo -n ”You must be ”

# -n keeps output on the same line and we need a space at the end

whoami

# whoami is a command/program

echo Your home is $HOME

# HOME is a variable

echo Your calendar for this month is:

cal # cal is a program

echo Friends on this computer $(hostname) are:

who # who and hostname are programs

echo ”Thanks for coming. See you soon!!”

Shell Scripts Page 5

Basic Shell Script Programming

Try out the shell script programs covered / to be covered in the lecture and follow through the statements

/ commands to understand how they work. Try the programs using different inputs. The symbol * is a

wildcard character that leads to the matching of filenames, etc.

#!/bin/bash

# There is a bug here, could you debug it?

read -p ”What was your score? ” score

echo You get a score of $score

# [ ... ] is for testing condition on an expression

# use gt > / ge >= / lt < / le <= / eq = / ne != for comparison, use –a and –o for and/or

if [ $score -ge 85 -a $score -le 100 ]; then

echo You got an A grade!

else if [ $score -ge 70 ]; then

echo You got a B grade

else

echo You better study!!

fi

fi

# a second way to express this

# use && and || to connect multiple testing expressions

if [ $score -ge 85 ] && [ $score -le 100 ]; then

echo You got an A grade!

elif [ $score -ge 70 ]; then

# elif is like else if, but using else if needs one more matching fi at the end

echo You got a B grade

else

echo You better study!!

fi

#!/bin/bash

# Try also using the notion of ;;& instead of ;; in some of them (works on apollo/apollo2)

read -p ”Which subject have you performed worst? ” code

case $code in

comp1*) echo ”$code is just a level 1 subject.” ;;

comp2*) echo ”$code is an intermediate level 2 subject.” ;;

comp[34]*) echo ”$code is a challenging senior level subject.” ;;

comp[56]*) echo ”$code is too advanced for you.” ;;

comp*) echo ”$code is unrecognized in comp.” ;;

*) echo ”$code is not a valid code.” ;;

esac

#!/bin/bash

# Is there any potential bug in the first for loop?

courselist=(1011 2021 2432)

for course in ${courselist[*]}; do

if [ $course -lt 2000 ]; then

echo level 1 course $course

else echo level 2 course $course

fi

done

# try list created by command (here it is ls)

for file in `ls`; do

echo file $file exists

done

# try list expanded from wildcard match (all C programs)

for f in *.c; do

echo $f is a C file

done

# try list expanded from a range

for i in {1..10}; do

echo i is $i

done

# try list expanded from a range of non-consecutive numbers

for i in {1..20..3}; do

echo i is $i

done

# try a C-style loop, need to use the syntax of (( ... ))

for ((i=1; i<=10; i++)); do

echo number is $i

done

# try handling input argument list

Shell Scripts Page 6

for item; do # absence of list implies the input argument list

echo one of the arguments is $item

done

#!/bin/bash

# Could you convert it to compute the factorial?

read -p ”Please enter a number: ” num

ctr=1 sum=0

while [ $ctr -le $num ]; do

sum=$((sum + ctr)) # same as let sum=sum+ctr

echo $ctr

let ctr++ # same as ctr=$((ctr+1))

done

echo ”The sum of $num numbers is $sum.”

#!/bin/bash

# Compare with the program based on while loop

read -p ”Please enter a number: ” num

ctr=1 sum=0

until [ $ctr -gt $num ]; do

sum=$((sum + ctr))

echo $ctr

let ctr++

done

echo ”The sum of $num numbers is $sum.”

#!/bin/bash

# Note that if this does not work for some of you due to the current file system in PolyU.

# You may do this under your own /webhome/12345678d,

# or make use of /tmp, which would still work under apollo or apollo2.

# Note that /tmp is shared between everyone using the machine,

# so please create your own subdirectory:

# $ cd /tmp

# $ mkdir myid12345678d

# $ cd myid12345678d

# // copy some files to here then try

for f in *; do # for each file in the current directory

if [ -d $f ]; then

echo $f is a directory

fi

if [ -f $f -a -x $f ]; then

echo $f is a plain executable file

fi

if [ ! -w $f ]; then

echo $f could not be modified

fi

done

#!/bin/bash

# Call this script testarg and try out different situations

echo ”This script is called $0”

if [ $# -eq 0 ]; then

echo ”No argument”

else

echo ”The number of arguments : $#”

echo ”The first argument : $1”

echo ”The last argument : ${!#}” # this returns the last argument

echo ”The full list : $@”

echo ”The fifth argument : $5” # how would you check that this fifth argument exists?

fi

#!/bin/bash

# Call this script filecp and try out different situations

# filecp dummy lab2Z.c

# filecp lab2A.c dummy

# filecp lab2A.c dummy # copy again

# filecp lab2A.c dummy # copy again, after making dummy not modifiable

cp $1 $2

if [ $? -eq 0 ]; then

echo ”File copied successfully”

else

echo ”Fail to copy file”

fi

Shell Scripts Page 7

#!/bin/bash

# Call this script chain and try out different situations

# Example: chain whoami pwd

# Example: chain whoami abc

# Example: chain abc whoami

# Example: chain abc def

# where abc and def are not commands nor executable files

echo first command is $1

echo second command is $2

echo ”executing $1 && $2”

($1) && ($2)

echo ”executing $1 || $2”

($1) || ($2)

# Executing command chain inside a testing condition

if [[ `$1` && `$2` ]]; then

echo ”both are successful”

else

echo ”some are not successful”

fi

if [[ `$1` || `$2` ]]; then

echo ”some are successful”

else

echo ”both are not successful”

fi

#!/bin/bash

# This script takes on two arguments (numbers) M and N

echo ’This script computes sum(1..M) + sum(1..N)’

num1=$1 num2=$2 # $1 and $2 are for script

echo Input M and N: $num1 $num2

function sumof { # first M/N, second returned sum

local ctr=1 sum=0 # local variables

while [ $ctr -le $1 ]; do # $1 is for sumof

let sum=sum+ctr ctr++

done

eval $2=$sum # $2 is for sumof and return

}

sumof $num1 r1

sumof $num2 r2

echo ”Sum of $num1 and $num2 numbers is $((r1+r2))”

File Transfer Protocol

[Optional]

The File Transfer Protocol or FTP allows you to upload files from PC to

computer system (at an ISP or to Unix or Linux) or download files from

computer system to your PC. A popular program on the PCs is the

WS_FTP program implementing FTP. However, it is not very secure and

has been replaced by Secure File Transfer Program (SFTP) in the

department. You can download the freeware WinSCP offering SFTP from

http://winscp.net/eng/download.php and install it. You need

to fill in csdoor.comp.polyu.edu.hk as hostname and select port 22 when

connecting from home. An equivalent software for FTP on the Mac is

Cyberduck. You can invoke Cyberduck to transfer files around. Do not

forget to choose the more secure SFTP protocol instead of FTP.

Note that if you are sending plain text files via FTP, you should use text format (this will automatically

correct those ^M monsters on Unix/Linux created by an editor on PC so that you do not need to use the

dos2unix or tr command). For other files, you should use binary format to ensure the correctness of

non-printable characters and foreign language characters (e.g., Chinese characters). If you are not sure

about the nature of your files, it is much safer to send them using binary format. Binary files include

program executables, Word files, Excel files, images, etc.

Shell Scripts Page 8

Publishing Web Pages via Unix / Linux

[Optional]

In Department of Computing, personal web pages accessible to the public are stored in Unix/Linux file

system. They must be placed under a special directory called public_html under your web home

directory (under your home directory in other normal Unix file systems). Directories must be at least

executable and files must be at least readable to other users. The default file accessed by web browsers

is index.html. Once you have created a set of web pages using Microsoft Expression Web or

Dreamweaver, you may try to publish them to the public. You have to upload those related files from

PC/Mac to Unix/Linux, perhaps using sftp / WinSCP or move them via J: drive. The web page files

must be stored under /webhome/12345678d/public_html. We must do some preparation work

to set the appropriate protection mode. Note: The preparation work only needs to be done once in

Unix/Linux. You may or may not need to set protection mode for your own directory in PolyU system,

but that is the default approach in most other Unix/Linux.

Change the protection mode of your own directory to drwx--x--x (i.e., 711) by typing

chmod 711 /webhome/12345678d

Create a sub-directory called public_html by typing

mkdir /webhome/12345678d/public_html

Change the protection mode of the directory to drwx—-x--x (i.e., 711) by typing

chmod 711 /webhome/12345678d/public_html

Now, invoke sftp or WinSCP to upload to Unix/Linux or copy the files to J: by yourself.

The files are now placed in Unix/Linux. There is one major subtle difference between PC and

Unix/Linux. In Unix/Linux, all web pages have file names ending with .html but in PC, all web pages

have file names ending with .htm. Depending on the web server, you may need to rename the file(s):

mv index.htm index.html

Now, you can explore your web pages using any browser. Your own homepage can be viewed at

http://www.comp.polyu.edu.hk/~12345678d

where 12345678d should be replaced by your own username. You may need to make some

adjustments to the contents of those web page files if you discover some minor problems, such as path

names. Also, you need to make sure that files for web pages are readable (chmod 644) and directories

are at least executable (chmod 711). It is now that the pico editor becomes useful when you need to

touch up in the file contents. However, you need to work directly with the “terrible” HTML formats. To

simplify, you may use zip to archive all the necessary files created with web tools into a zip file and

place it under Unix/Linux. For your information, Unix/Linux people often use the tar command to

archive files. Finally, you can extract the files from the zip file and set the appropriate protection mode

for files and directories.

Shell Scripts Page 9

Laboratory Exercise

Write a bash shell script called euro to input the scores of UEFA Champions League group stage

matches and draw up the league tables for the teams. The 32 teams are divided into 8 groups, each group

with 4 teams. The winner of a match will be awarded 3 points, the loser 0 point. In case of a draw, both

teams will be awarded 1 point. Your program then reads in a sequence of files containing the scores of

matches in different rounds, as indicated by the prefix of those files as the parameter. The outputs should

be divided into the groups, ranked by points. Your program should work on any set of valid inputs, not

necessarily on the real-life inputs derived from the scores of actual matches.

The actual tie-breaking rules in Champions League are very complicated, inclusive of head-to-head

results, away goals, minor league for multi-way ties, and even up to red and yellow cards (disciplinary

points). We will be adopting a much simplified set of tie-breaking rules. If there is a tie, the first tie

breaker is by goal difference, then by number of goals scored, finally by team name. For example,

Liverpool will still rank before Napoli if Napoli were to draw 2:2 with RedStar in the first

match instead of 0:0. InterMilan will rank before Tottenham if InterMilan were to beat PSV

by 5:4 instead of 2:1 in the second match. Note that if the actual Champions League tie-breaking rules

were adopted, Tottenham would always be ahead of InterMilan, regardless of whether

InterMilan beated PSV by 2:1, or 5:4, or even 6:5, since Tottenham would be ahead based on

away goals for the two head-to-head matches. You could test the correctness of your program by

changing the scores in the input files.

In a properly formed schedule, each team in each group will face each other exactly twice, one at home

and one away. You can assume that there is no error in the information contained in each file. In other

words, you do not need to handle errors in the score files.

For instance, the program can be run like:

euro score18

Here, score18 is the prefix of the files containing the match scores, e.g. score18Rount1,

score18Round2. Each line of the score file contains the score of a match. The first element is the

group name, followed by the first team, the goals scored and then the second team. The first team is the

home team and the second team is the visiting team. For simplicity, you can assume that there is no

space in the team name. You may consider using the back quote operator in a for-loop to extract all

information. Typical file contents are shown below:

Filename Content

score18Round1 Group B Barcelona 4 0 PSV

Group B InterMilan 2 1 Tottenham

Group A Brugge 0 1 Dortmund

Group D Schalke 1 1 Porto

Group A Monaco 1 2 Madrid

Group C Liverpool 3 2 PSG

Group C RedStar 0 0 Napoli

Group D Galatasaray 3 0 LokoMotiv

Group E Ajax 3 0 AEK

Group F Shakhtar 2 2 Hoffenheim

Group G RealMadrid 3 0 Roma

Group H Valencia 0 2 Juventus

Group E Benfica 0 2 Bayern

Group G Plzen 2 2 CSKA

Group F ManCity 1 2 Lyon

Group H YoungBoys 0 3 ManUnited

score18Round2 Group F Hoffenheim 1 2 ManCity

Group H Juventus 3 0 YoungBoys

Group E AEK 2 3 Benfica

Group G CSKA 1 0 RealMadrid

Group E Bayern 1 1 Ajax

Shell Scripts Page 10

Group H ManUnited 0 0 Valencia

Group F Lyon 2 2 Shakhtar

Group G Roma 5 0 Plzen

Group C PSG 6 1 RedStar

Group D LokoMotiv 0 1 Schalke

Group C Napoli 1 0 Liverpool

Group D Porto 1 0 Galatasaray

Group B PSV 1 2 InterMilan

Group A Dortmund 3 0 Monaco

Group B Tottenham 2 4 Barcelona

Group A Madrid 3 1 Brugge

score18Round3 Group E AEK 0 2 Bayern

Group H YoungBoys 1 1 Valencia

. . .

The output of your program should look like, after processing upon all the files in this season (formatting

is not important):

Group A

Team W D L Point GoalF GoalA GoalD

Dortmund 4 1 1 13 10 2 8

AtlMadrid 4 1 1 13 9 6 3

Brugge 1 3 1 6 6 5 1

Monaco 0 1 5 1 2 14 -12

Group B

Team W D L Point GoalF GoalA GoalD

Barcelona 4 2 0 14 14 5 9

Tottenham 2 2 2 8 9 10 -1

InterMilan 2 2 2 8 6 7 -1

PSV 0 2 4 2 6 13 -7

Group C

Team W D L Point GoalF GoalA GoalD

PSG 3 2 1 11 17 9 8

Liverpool 3 0 3 9 9 7 2

Napoli 2 3 1 9 7 5 2

RedStar 1 1 4 4 5 -17 -12

. . .

Group H

Team W D L Point GoalF GoalA GoalD

Juventus 4 0 2 12 9 4 5

ManUnited 3 1 2 10 7 4 3

Valencia 2 2 2 8 6 6 0

YoungBoys 1 1 4 4 4 12 -8

Requirements:

1. Elementary level: your script can read in the match scores from one file and display the number of

goals-for and goals-against for teams correctly.

2. Basic level: your script can read in the match scores from all files and compute the number of wins,

draws and losses, as well as goals-for, goals-against and goal differences for teams in the group tables

correctly.

3. Required level: your script can produce the correct sorted output with information correctly computed.

4. Bonus level: your script can group the teams together without having to rely on the group name in the

file (e.g. assuming that all group names were changed to “Z”). Of course, the names and the ordering of

the eight groups will become unspecified in this case. To be more adventurous, you might also try to

implement the actual tie-breaking rules adopted by the UEFA Champions League, assuming that you

would not need to use the red and yellow card information for final tie-breaking.

Name your program euro and submit it via BlackBoard on or before 15 February 2019.




站长地图