Today i was facing problem while running a tcl script on linux. This tcl script was extracted from a zip file copied on machine through WinScp. Now the problem was that after unzipping the file , its format remained same.
When i was trying to execute the script, it was showing “: bad interpreter: No such file or directorybin/tclsh”. In the file there was written “#! /usr/bin/tclsh” . I found that everything is same in a different script file, but that is
running successfully. What could be the reason. Then suddenly my eye were on the bottom of the terminal, where it was showing “script2.tcl” [dos] 748L, 30804C” . Thought this might be the culprit. Then i needed to
convert the file format from DOS to UNIX. So i googled to get vim site. I followed the instructions:
A. I am just pasting the same instructions that i followed
- Convert from dos/unix to unix
To convert the current file from any mixture of CRLF/LF-only line endings, so all lines end with LF only:
:update |
Save any changes. |
:e ++ff=dos |
Edit file again, using dos file format ('fileformats' is ignored).[A 1] |
:setlocal ff=unix |
This buffer will use LF-only line endings when written.[A 2] |
:w |
Write buffer using unix (LF-only) line endings. |
In the above, replacing :set ff=unix
with :set ff=mac
would write the file with mac (CR-only) line endings. Or, if it was a mac file to start with, you would use :e ++ff=mac
to read the file correctly, so you could convert the line endings to unix or dos.
B. It has also way to convert Unix to Dos:
- Convert from dos/unix to dos
To convert the current file from any mixture of CRLF/LF-only line endings, so all lines end with CRLF only:
:update |
Save any changes. |
:e ++ff=dos |
Edit file again, using dos file format ('fileformats' is ignored).[A 1] |
:w |
Write buffer using dos (CRLF) line endings. |
Note: After this i went on to find that there are two similar programs which we can install on linux machine.
1. dos2unix
2. unix2dos
Recent Comments