What error are you getting?
Just by looking at what you posted, you might try:
This won't work with all shells, though. Most likely, it will work with ksh and zsh, but not sh or bash. Also, you can remove the "cat" at the beginning, and redirect the file into done: