Shell Script error:-bash: xxx:/bin/sh ^ M: badinterpreter: Nosuchfi

Source: Internet
Author: User
Today, I wrote a shell script and reported an error during execution. the script content is simple and only for testing: Shell Code :#! /Bin/shecho & quot; testshell & quot; the specific error message is as follows: Shell code: [root @ localhosttest] #. /test. sh-bash :. /test. sh:/bin/sh ^ M: bad... today, I wrote a shell script and reported an error during execution. the script content is simple and only for testing:
Shell Code :#! /Bin/sh
 
The echo "test shell" error message is as follows:
Shell code: [root @ localhost test] #./test. sh
-Bash :. /test. sh:/bin/sh ^ M: bad interpreter: No such file or directory since I was not familiar with shell before, I learned about the source Committee after communicating with my colleagues, mainly because of test. sh is edited in windows and uploaded to linux for execution .. The sh file is in dos format. Linux can only execute scripts in unix format.
We can use the vi editor to view the file format. The procedure is as follows:
1. run the vi command to open the file.
Shell code: [root @ localhost test] # vi test. sh 2. use the: set ff command in the vi command mode.

The file format is dos.

3. modify the file format to unix
Method 1: Use vi to modify the file format
Command: set ff = unix

Run the set ff command to view the file format. The result is as follows:

Method 2: directly use the dos2unix command to modify
Shell code: [root @ localhost test] # dos2unix test. sh
Dos2unix: converting file test. sh to UNIX format... after modification, run./test. sh again. The execution is correct:
Shell code: [root @ localhost test] #./test. sh
Test shell
 

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.