A workaround for "No file or directory" prompt in shell script execution

Source: Internet
Author: User
The cause of the bad interpreter:no such file or directory is an issue 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.
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:

Sed ' s/^m//' filename > tmp_filenamemv-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)

   #!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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.