How to replace Windows new line characters in Ubuntu

Recommended Ubuntu book

I have tried executing a bash script edited in Windows, which gave me an error:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ sh /vagrant/scripts/
: not foundripts/ 2: /vagrant/scripts/
/vagrant/scripts/ 4: set: Illegal option -

I tried executing it with bash, which gave me more details showing windows new line character as a problem:

vagrant@vagrant-ubuntu-trusty-64:/var/www/magento2$ bash /vagrant/scripts/
/vagrant/scripts/ line 2: $'\r': command not found
: invalid option/ line 4: set: -

To solve this problem, I replaced Windows new lines with Linux:

sed -i 's/\r$//' /vagrant/scripts/

If you have this problem, replace filename with the name of your file:

sed -i 's/\r$//' filename

Comments are closed.