Multiple choice questions with diagnotic answers
Both of my multiple choise questions are building on the lessons about Shell Pipes and Filters.
Question 1
Which of the following combination of shell commands will return the
output Welcome
. (If you not familiar with the commands: echo
will
give a string to the standard output; tr
will replace one string by
another one, sort
return sorted lines; tail
will give the last
lines of a given input (-n
specifies the number of lines)).
echo "Welcome to the shell" | tr " " "\n" | sort | tail -n 1
echo "Welcome to the shell" ; tr " " "\n" ; sort ; tail -n 1
echo "Welcome to the shell" > tr " " "\n" > sort > tail -n 1
echo "Welcome to the shell" < tr " " "\n" < sort < tail -n 1
Question 2
Let us assume we have the plain text file fruits.txt
with the
following 12 lines of content:
peach
apple
banana
orange
avocado
cherry
strawberry
pineapple
blueberry
pear
kiwi
clementine
What will be the outcome of the following commands.
cat fruits.txt | head | wc -l
- Nothing as
head
andwc
do not have any input files 12
10
10 10 77
What can the different answer tell us about misconception of the student?
- The student does not know how Unix shell pipes work. I.e. that the
output of one command that is given to the standard output is used by
the next command connected by
|
as standard input. - The student is not aware that
head
will show per default only the first 10 lines of a file. - The correct answer
- The student is not aware the impact of the parameter
-l
of the commandwc
.