The reason for bad interpreter:no such file or directory is the file format problem. This file is written under Windows. Line-wrapping is not the same as UNIX, but under vim if it is not set it is completely invisible.
Problem Analysis:
1, will be prepared under Windows shell file, uploaded to Linux under the implementation, prompted error.
2, error message: Bad interpreter: no file or directory.
Problem Reason:
Because the operating system is windows, the script is edited under Windows, so there may be invisible characters. Script file is in DOS format
That is, the end of each line is identified by \ r \ n, and its ASCII code is 0x0d, 0x0A.
Workaround:
There are a number of ways to see whether this file is in DOS or UNIX format or Mac format.
(1) Vim filename
Then use the command: set FF
You can see the words DOS or UNIX, if it is a DOS format, then use set Ff=unix to force it to UNIX format, and then save the file to run.
Text file formats that convert different platforms can be used
1. Unix2dos or Dos2unix These two small procedures to do. Very simple. In DJGPP, the names of the two programs are called Dtou and Utod, u on behalf of UNIX, D for DOS
2. Tools such as SED can also be used:
Copy Code code as follows:
Sed ' s/^m//' filename > Tmp_filename
Mv-f tmp_filename filename
Special Note: ^m is not a key shift + 6 generated ^ and letter M, it is a character, its ASCII is 0x0d, the way to generate it is to press CTRL + V before you enter (or ctrl+m)
In addition, when the Shell Program reports command not found, always check your path for every command that is not used by the program (the one that does not specify an absolute path). You are so small a program, you can check it line by line.
Attach: Write less one/throw the problem without that file or directory
Today, looking at a simple shell script written earlier, I found a problem:
Always prompt when./Run: (bash:./hello.sh:bin/bash: Bad interpreter: No file or directory), but correct when running with SH.
The original script:
(Try to see if you can make a mistake)
Copy Code code as follows:
#!bin/bash
echo "Hello linux!"
After a few tests, I found myself missing something.
We should change the first line into #!/bin/bash, write less one/
Alas, a very simple question, I have not found that there is such a mistake before! The shell script really works, but the only difficulty is that the format is too high!