Linux execution Shell script hint file cannot find problem resolution __linux

Source: Internet
Author: User

When executing a pre-existing shell script file under a Linux system, it prompts you that the file does not exist.

The general reason for this is that your shell script is written in a system that is inconsistent with your execution script, such as the script you wrote in the window system, and you will encounter this problem when you copy it to the Linux system. The reason is that the. sh file edited under Windows is in DOS format, and 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. In addition, when you use Windows system to download the source file containing the shell script file on the GitHub, this problem may also occur when you extract and copy the Linux system execution.


Solution:

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 the format of the file as
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 exit, rerun script is normal


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.