Symptom: In terminal direct Cd/var normal, execute in shell script is error. The reason is that the script is written under the Windows platform, and the line break is different from Linux, causing the script to not execute correctly
The cause of bad interpreter:no such file or directory (there is no file or directory) is a problem with the document format. This file was written under Windows. Line wrapping is not the same as UNIX, but under vim if it is not set a bit and it is completely invisible.
Problem Analysis:
1. Write the shell file under Windows and upload it to Linux to execute, prompting for error.
2, error message: Bad interpreter: There is no file or directory.
Cause of the problem:
Because the operating system is windows, the script is edited under Windows, so there may be non-visible characters. The script file is in DOS format
That is, the line end of each line is identified by \ r \ n, and its ASCII code is 0x0d, 0x0A, respectively.
Workaround:
There are many ways to see if the file is in DOS or UNIX format, or in MAC format.
(1) Vim filename
Then use the command: set FF
You can see the Word dos or UNIX, if it is a DOS format, then use set Ff=unix to enforce it in UNIX format, and then save the disk to run.
(Set Ff=unix: Tell vi editor, use UNIX newline character, personal use above method solves, simple and convenient, recommend this way)
############## #分割线 ##############
The text file format for converting different platforms can be used
1. Unix2dos or Dos2unix These two small programs to do. Very simple. In DJGPP the names of these two programs are called Dtou and Utod, U is UNIX, D is DOS
2. You can also use tools such as sed to do:
Copy CodeThe code is as follows: sed ' s/^m//' filename > Tmp_filename
Mv-f tmp_filename filename
Special Note: ^m is not a key SHIFT + 6 produced by the ^ and the letter M, it is a character, its ASCII is 0x0d, the way to generate it is to first press CTRL + V, then enter (or ctrl+m)
Also, when the Shell Program reports command not found, always check to see if there are any commands in your path that are not being used by the program (the one that does not specify an absolute path). You are such a small program, you can check the line.
Attachment: Write less one/raise no problem with that file or directory
Today, looking at the simple shell script that I wrote earlier, I found a problem:
When./runtime always prompt: (bash:./hello.sh:bin/bash: Bad interpreter: No file or directory), but when running with SH is correct.
The original script:
(Try to see if you can make a mistake)
Copy CodeThe code is as follows:
#!bin/bash
echo "Hello linux!"
After a few checks, I found that I had lost something in my writing.
The first line should be changed to #!/bin/bash, one less write/
Alas, very simple question, I have not found that there is such a mistake before! Shell scripts are really good, but the only hard part is that the formatting requirements are too high!
Tips for bad interpreter:no such file or directory when executing shell scripts