Write and run shell scripts

Source: Internet
Author: User
Write and run shell scripts-Linux general technology-Linux programming and kernel information. The following is a detailed description. [I = s] This post was last edited by tjwangzhen

Run the. sh script in Linux./bin/sh ^ M: bad interpreter: No such file or directory is abnormal.
Analysis: This is caused by different system encoding formats: the. sh file edited in windows may have invisible characters, so the preceding exception information is reported when executed in Linux.
Solution: 1) conversion in windows: use some editors, such as UltraEdit or EditPlus, to convert the script code before running it in Linux.
The conversion method is as follows (UltraEdit): File --> Conversions --> DOS-> UNIX.
2) conversion can also be performed in Linux: first ensure that the file has executable permissions # chmod a + x filename and then modify the file format
# Vi filename use the following command to view the file format: set ff or: set fileformat. you can see the following information: fileformat = dos or fileformat = unix use the following command to modify the file format: set ff = unix or: set fileformat = unix: wq (save disk exit) and then execute the file #. /filename

Compile and execute the. sh script
Gedit filename. sh
Save after writing
Change execution permission
Chmod a + x filename. sh
Then run./filename

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.