Exam Questions

The answers should be in the form of a single text file that you will submit by mail to thomas.junier@sib.swiss or robin.engler@sib.swiss. Please number the answers according to the questions, e.g.

Question 2

(your answer here)

You are encouraged to have a look at all the questions before answering them.


Question 1

What will the following command output?

$ name=Hypatia
$ echo $name "$name" '$name'


Question 2

Why doesn't this work and how would you fix it so that $ echo $species outputs the full scientific name?

Give at least two methods.

$ species=Bos taurus


Question 3

Variable sequence contains a DNA sequence with ambiguous nucleotides (IUPAC symbol R, which stands for A or G). Show how parameter expansion can be used to replace all instances of R in $sequence by [AG].

ambig_sequence="CGGCRATACRGCGAT"


Question 4 - Complement a sequence

Write a script that complements a DNA sequence. Assume all nucleotides are unambiguous (i,e, only A, T, G, and C) and in uppercase letters. The sequence should be the first (and only) argument

Hint: to avoid confusing an original G with a G resulting from complementation of C, etc., you can use lowercase g.

e.g.

$ ./complement.sh GAATTC
CTTAAG


Question 5 - Reverse

Write a script that reverses a sequence

Hint: man rev

$ ./reverse.sh TTAAAC
CAAATT


Question 6 - Reverse-complement

Write a script that reverse-complements a sequence

$ ./revcomp.sh TTAAAC
GTTTAA
$ ./revcomp.sh GAATTC
GAATTC


Question 7

Explain the following unexpected behaviour:

a=2; [[ a+a == a*a ]] # true
a=2; [[ a*a == a+a ]] # false


Question 8

A shell user typed the following, and it worked as expected:

a=2; ((a>0)) && echo "a is greater than 0"

However when the user typed this:

a=2; [[a>0]] && echo "a is greater than 0"

it failed miserably. The user asks you first to provide a quick solution. What do you reply?

Then, the user -- being eager to understand -- asks you "Why does the shell behave like this? That is, what general principle causes the first command to succeed and the second to fail? In other words, what do I need to understand in order to avoid this kind of error (not just that particular one) in the future?

What is your reply?

Last modified: Tuesday, 4 May 2021, 4:03 PM