UNIX/Linux Shell Script Quiz

We have just a handful of questions to test your knowledge of shell script syntax. It's not as easy as you might think! You should be able to figure out all the answers to all these questions from our shell script lessons found on the homepage.

What will be the output of   "echo this || echo that && echo other"?

this
that
this
other
this
that
other
other

How could you check if two strings are equal?

test $a -eq $b
test $a -equal $b
test $a = $b
sh -c test $a == $b

Which of the following would return the process ID of the sleep command?

sleep 1 & echo $?
sleep 1 & echo $#
sleep 1 & echo $$
sleep 1 & echo $!
sleep 1 && echo $0
test sleep 1

Which of the following will always output "maple"?

$tree=maple; echo $tree
tree = maple ; echo $tree
export tree = maple; echo $tree
tree=maple; export $tree; sh -c "echo $tree"
tree=maple; export tree; sh -c "echo $tree"

Which of the following will output "cat"?

case "dog" in
*) echo cat ;;
esac
case "cat" in
cat) echo $1
exit
case cat dog rabbit; echo $1
echo cat | case $1 in
cat) echo $1 ;; esac
case (cat dog rabbit) { echo $2 }

Which of the following will output "onetwothree"?

for val ; do echo -n $val ; done < one two three
for n in one two three ; do echo -n $n ; done
for one two three ; do echo -n - ; done
foreach n in one two three ; do echo -n $n ; done
foreach n in one two three { echo -n $n }
for n in one two three { echo -n $n }