I just executed same script in my centos machine which works file. As suggested by AftabKusalananda, convert the script file from dos to unix. install dos2unix package if you do not have it installed already. Then you can use below command to convert $dos2unix (name of the file)