This isn't a terminal issue. I suspect a shell issue.
Specifically, that $'...'
notation is a bash-specific extension, but you are running the script simply by sh
and not bash
, so it won't apply.
Try changing the shebang line in the script to
#!/bin/bash