Implemented all the chapter 2 exercises.

There are 4 exercises in the chapter. I implemented
all of them. I also added a hash-bang directive
so it can execute as a shell script without specifying
the interpreter.