Scripts uploaded from Windows to Linux cannot be executed

Source: Internet
Author: User

In the local windows, wrote a shell script, using SFTP or other methods to upload the script, execute the script appears no such file or directory prompt, see the script encoding and permissions are no problem, create a new file under Linux, copy the script contents, Content is exactly the same, but can be executed.

Cause: Windows line break symbol is "\ r \ n", and Linux is "\ r" does not "\ \ \", when the shell script is written under Windows, the default all line break is "\ r \ n", Linux is not able to correctly identify the file, will prompt the above error , you can use a third-party editor, such as UltraEdit, to convert the file to UNIX format and execute "File->conversions->dos to Unix", which is to delete the "\ r" symbol.

A simple solution under Linux:

  1. Modified file: sed-i ' s/\r$//g ' filename manually delete ' \ r ' symbol

  2. After Vim opens the file, the command mode executes: Set Ff=unix, then save on the line

  3. Converting files using the Dos2unix command

Scripts uploaded from Windows to Linux cannot be executed

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.