I recently asked a question on stackoverflow and then found out that my mistake had nothing to do with what I expected. So the script posted in my question was perfectly valid and the mistake took place elsewhere in the setup.
Should I mark my question for deletion, accept my own answer, or what is the way to go here? Perhaps the (little) knowledge contained in my question could still be useful to someone in the future.