OS X bash: dirname
What finally worked for me is changing this:
#!/bin/shcd `dirname $0`
To this:
#! /bin/zshcd "${0:h}"
This also supports file names and file paths containing spaces. Here's where I found it: http://rentzsch.com/unix/locationAwareCommandFiles