made more robust, workaround for -sh on OS X