modified script to work in bash correctly (tested on ubuntu 12.04 LTS)

fixes issue #16. I am not sure about the effect on other shell environments. This can be discussed in the issue report.