Glad I could help.
By the way it should have worked as written (and did for me). However, whatever works is always the "right" way to do it. Technically the way you did it is the "new" way and the way I did it is the "old style" (according to bash man page).
I wonder if perhaps you had an issue on the following line:
for file in `ls $directory`
Note that the character here is the backtick (`) rather than the single quote ('). Back tick usually being the lower case symbol on the same key as the tilde (~). Single quote being the the lower case on the same key as the double quote ("). Backtick is a/k/a "accent grave or backquote".
If you used the single quote instead of backtick you would have had an issue.
I doubt there is a version of bash that doesn't use the backtick special meaning. That would be a major change to functionality requiring rewrite of many scripts.