I do not know much about Linux. I have worked on it whenever I get a chance and have written a few shell scripts. But yet, this is relatively unfamiliar territory for me. Recently I came across this issue when running my shell scripts - "/bin/bash^M: bad interpreter: No such file or directory". This message is pretty obvious and means that some 'not-so-obvious' characters are introduced in the file, leading to these errors.
This issue occurs normally when one tries to edit files in Windows (using some of those fancy editors) and then copy into a Linux machine. At least that's what I had done. The first time I used dos2unix command to get rid of these unseen (^M) characters. The second time I tried the same, I found that dos2unix utility was not installed in my machine. This drove me into finding alternative solutions and here's what I found.
Open the file in question using vi and try typing the following (after pressing 'Esc'). Once done save the file using Esc, :wq.
Solution 1:
:%s/{Ctrl-v}{Ctrl-m}//g
where {Ctrl-v} refers to pressing 'Ctrl' and 'V' at the same time. Likewise for {Ctrl-m}
Solution 2:
:set ff=unix
Note: This is the one that worked for me.
Solution 3:
%s/{Ctrl-M}\+$//
This issue occurs normally when one tries to edit files in Windows (using some of those fancy editors) and then copy into a Linux machine. At least that's what I had done. The first time I used dos2unix command to get rid of these unseen (^M) characters. The second time I tried the same, I found that dos2unix utility was not installed in my machine. This drove me into finding alternative solutions and here's what I found.
Open the file in question using vi and try typing the following (after pressing 'Esc'). Once done save the file using Esc, :wq.
Solution 1:
:%s/{Ctrl-v}{Ctrl-m}//g
where {Ctrl-v} refers to pressing 'Ctrl' and 'V' at the same time. Likewise for {Ctrl-m}
Solution 2:
:set ff=unix
Note: This is the one that worked for me.
Solution 3:
%s/{Ctrl-M}\+$//
No comments:
Post a Comment