Windows Write shell script in Linux execution error resolution _linux shell

Source: Internet
Author: User

Write a shell script under Windows, upload to Linux run the Times wrong:

Copy Code code as follows:
[Root@localhost test]#./test.sh
-bash:./test.sh:/bin/sh^m:bad interpreter:no such file or directory

Test.sh Source:
Copy Code code as follows:
#!/bin/sh

echo "Test Shell"

Because I am not familiar with the shell, to find colleagues to understand the cause of communication, the main reason is that test.sh I edited in Windows and uploaded to the Linux system to execute the format of the. sh file is in DOS format. Linux can only execute scripts formatted as UNIX. Because under the Dos/window press the return key to actually enter is "returns (CR)" and "line break (LF)", and Linux/unix press the return key to enter only "line break (LF)", so the modified SH file in each line will be more than one CR, So Linux running under the error can not find the command.
We can view the format of the file by using the VI editor. The steps are as follows:
1. First open file with vi command
[Root@localhost test]# VI test.sh
2. Use in VI Command mode: SET FF command
You can see that the format of the change file is

Copy Code code as follows:
Fileformat=dos

3. modify file format to Unix
Use Vi/vim to modify file format
Command:: Set Ff=unix
Or:: Set Fileformat=unix

Then: Wq Save the exit on it

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.