Use 'read -n' instead of 'head -c' to improve compatibility

Fixes #519