Running a script created in Notepad (Windows) on Ubuntu

Windows and Linux have different end-of-line symbols.

You can install the dos2unix utility that fixes it:

sudo apt-get install dos2unix

Run it this way:

dos2unix -n winfile.txt linuxfile.txt

There is also the unix2dos utility.

The Windows-to-Linux conversion can also be done without installing any special software by

 tr -d '\r' < winfile.txt > linuxfile.txt

Note: Input and output files must be different.

A sed version will edit the file "in place":

 sed  -i 's/\r//g' file.txt

Or write to another file:

 sed 's/\r//g' winfile.txt > linuxfile.txt

On Windows, you need to change the End of Line (EOL) format in Notepad++ to UNIX:

enter image description here

That way it will work on Ubuntu too.


Windows uses CR+LF for line breaks. In Linux/Unix you need LF. Therefore you have to replace CR+LF into LF in your script:

Install dos2unix

sudo apt-get install dos2unix

And correct your script via

dos2unix <your_script_file>

or via

dos2unix -n <your_script_file> <out_file>

if you need a different output file

More informations here


from man dos2unix

NAME
       dos2unix - DOS/Mac to Unix and vice versa text file format converter

SYNOPSIS
           dos2unix [options] [FILE ...] [-n INFILE OUTFILE ...]
           unix2dos [options] [FILE ...] [-n INFILE OUTFILE ...]