If you’re a regular vi user, you may have noticed that some files, when being edited in vi, contain ^M characters at line ends.
This usually happens when you edit a file using certain windows-editors, then transfer it to your *nix machine.
Luckily, it is easily to get rid of this control character. While in vi, execute the following command:
Important note: do not manually type a caret then the capital M character. Actually, in order to type ^M, press CTRL+V followed by CTRL+M.
A quick note: the above command will look for the ^M character starting on line 1, substituting it ($s) with nothing (thus having the two consecutive forward slashes / with nothing in between). And this substitution is performed globally (g).