compatibility for posix "sh"

Tested these changes on my computer and it seemed to work OK. Hope it actually works correctly! :-)