Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Dos2unix unix2dos se ff=uni

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report