in reply to exec problem

The reason why it "hangs", is because you're having a case of endless recursion: there is no condition on which the function doesn't recurse.

But I'm not sure why you're using env. What does it buy you that simply setting %ENV and continuing with the rest of the script, wouldn't?