reimplemantation using bash instead of posix shell