You are on page 1of 4

York University

Lassonde School of Engineering


Dept. of Electrical Engineering and Computer Science
EECS 2031
Software Tools
Fall 2018
EECS2031 Lab Test 1_A Software Tools
Friday, Nov. 26th 2018 4:30– 6:30pm
Question 1 (6 points)
Write a bash script that displays the number of courses a student is registered in.
The program checks two files
The first file NameID.txt which contains students ID and students names. The ID is a 6
digit decimal number, and the name could be on one of three formats.
i. First name last name
ii. First name middle initial last name
iii. First name middle name last name
Eample
123456 John Doe
345678 John P. Doe
987654 John Public Doe
Keep in mind that these three names are for three different students.
The second file NameCourse.txt is on the form Course number, Student Name
Example
EECS2021 John Doe
EECS2021 John P. Doe
EECS2031 John Doe
EECS4201 John Doe
The program reads a student ID without any prompt, and then it displays the number of
courses the student is registered in. If the student is not registered in any course displays
0
CPU % q21.sh
123456
3
CPU % 
Where John Doe (with ID=123456) is registered in 3 courses

Submit as 2031 L1A q21.sh be sure it is executable

Lab Test 1 EECS2031 Page 1


Fall 2018 York University Lassonde School of Eng.

Question 2 (4 points)
Write a shell script that accepts no command line arguments. The script reads three
integers from the standard input. If the three integers are in an ascending order; it prints
the median number and quits
If the three numbers are not in an ascending order, it displays NO and proceeds to read
three integers and repeat until three ascending numbers are read; then it displays the
median number and quits.

for example
CPU % q22.sh
334
NO
362
NO
345
4
CPU% 

Submit as 2031 L1A q22.sh be sure it is executable

Lab Test 1 EECS2031 Page 2


Fall 2018 York University Lassonde School of Eng.

Question 3 (6 points)
Write a bash script that takes no command line arguments and reads one number from the
standard input with no prompt. If there is a command line argument, it displays
No command line arguments please, and proceed to read one integer.
If the integer read could be the diagonal of a right angled triangle with the other two sides
are integers, then it prints YES, otherwise prints NO on the standard output.

CPU % q23.sh 17
No command line arguments please
7
NO
CPU% 
CPU % q23.sh
5
YES
CPU% 

Submit 2031 L1A q23.sh Be sure it is executable

Lab Test 1 EECS2031 Page 3


Fall 2018 York University Lassonde School of Eng.

Some Functions you might need 
Positional Parameters

$0 The name of the script

$1 $2 …. $9 The different positional parameters


${10} ….
$* list of all positional parameters

$# The number of parameters

$@ list of all arguments differs from $*


only when in double quotes
$? The exit status of the process

$$ The pid of the current shell (not


subshell)
$IFS The input field separator

1. if [ <condition> ]
2. then
3. statements
4. elif
5. then
6. statements
7. elif
8. then
9. statements
10. else
11. statements
12. fi

1. while [ condition ]
2. do
3. ……
4. done

Lab Test 1 EECS2031 Page 4

You might also like