Dos2unix unix2dos se ff=uni
Problems and solutions
Write a shell script in notepad under windwos. It's OK to run it under cygwin, but
There will be a problem when you run it under linux, which shows:
: bad interpreter:no such file or directory
The cause of the problem is the "line Terminator", unix/linux uses a newline character, while dos/windows makes
Use enter + line change
Solution:
1. Open the script using vi
two。 Set fileformat (ff)
: set ff=unix
3. Save
: w test.sh
At this point, test.sh can be executed under linux (pay attention to whether it can be executed before running)
Note: under cygwin, fileformat is either unix or dos
Example one: the performance of DOS format text file under Linux
Now there is a script file job.sh, which is edited with vi under Linux.
[root@jfht ~] # cat job.sh
#! / bin/sh
Date > job.txt
Now convert it to a DOS format text file.
[root@jfht ~] # unix2dos job.sh
Unix2dos: converting file job.sh to DOS format...
Try to run it.
[root@jfht ~] #. / job.sh
-bash:. / job.sh: insufficient permissions
[root@jfht ~] # chmod + x job.sh
[root@jfht ~] #. / job.sh
-bash:. / job.sh: / bin/ sh ^ M: bad interpreter: there is no such file or directory
Cannot be interpreted and executed in a script file in DOS format, because the first line of the script file is used to specify the interpretation
The Linux system thinks the interpreter is / bin/ sh ^ M, not / bin/sh.
Let's take a look at the true face of a file in DOS format through some commands under Linux.
[root@jfht ~] # cat-v job.sh job.txt ^ M
^ M
[root@jfht ~] # hexdump-C job.sh job.txt.... |
0000001e
[root@jfht ~] # vi job.sh job.txt
~
~
"job.sh" [dos] 4L, 30C
Now let's change the DOS format back to Unix format and see how it works.
Root@jfht ~] # dos2unix job.sh
Dos2unix: converting file job.sh to UNIX format...
[root@jfht ~] #. / job.sh
Can be executed, do not report "- bash:. / job.sh: / bin/ sh ^ M: bad interpreter: no"
That file or directory "this is wrong.
[root@jfht ~] #
Example two examples of the use of dos2unix-k and dos2unix-n
[root@jfht ~] # cat 1
> 2
> 3
> EOF
[root@jfht ~] # file 1.txt
1.txt: ASCII text
[root@jfht ~] # ls-l 1.txt
-rw-r--r-- 1 root root 6 11-14 09:08 1.txt
[root@jfht ~] # date
Sunday, November 14, 2010, 09:28:42 CST
[root@jfht] # unix2dos-k 1.txt