Use /bin/bash instead of /bin/sh.

'read -d' is dependent on bash.