Collection and collation #! Bin/sh

Source: Internet
Author: User
Tags perl script

The first time I learned shell programming, I read the article that the shell program must start "#! /Bin/sh.

Although I know that all statements starting with "#" in shell are comments, I never think "#! /Bin/sh is also a comment, just as there is no doubt that a C program must have a main function.

But some time ago I heard that "#! /Bin/sh "is also a comment and dispensable. At that time, I thought it was a failure and I couldn't even tell the basic syntax.

I borrowed a book a few days ago, so I really got to know me "#! /Bin/sh ".

Shell programming is annotated with "#", but "#! /Bin/sh ", but not.

"#! /Bin/sh "is the shell declaration, indicating that you are using the shell type and its path.

If no declaration is made, the script will be executed in the default shell. The default shell is defined by the user's system as the shell for executing the shell script.

For example, if the script is written to run in Korn Linux and the C shell CSH is run by default, the above script may fail to be executed.

Therefore, we recommend that you set "#! /Bin/sh "is the same as the main function in C language. It is required to write shell to make Shell programs more rigorous.

 

That is :#! /Bin/sh indicates that the script is interpreted and executed using/bin/sh ,#! Is a special identifier, followed by the path of the shell that explains the script.

In fact, the first sentence #! It is the interpreter program path for the script. The content of the script is explained by the interpreter. We can use various interpreters to write the corresponding script.

For example, the/bin/CSH script,/bin/perl script,/bin/awk script,/bin/SED script, And/bin/ECHO script.

Can we write a/bin/ECHO script file? Let's try it. The following is an example:

Code:

#! /Bin/ECHO-e

This only has one line of Program (in fact it can only be one line, Echo program is not designed as a programming language like awk, can be written as a source program file) named myecho, add the permission and execute it:
Code:

$./Myecho "Hi \ A"./myecho hi

If your echo supports the-E Option and your work environment is still quiet, you should also hear the crisp terminal ring when you get the above results. But such a program is useless.

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.