Function of Shell programming

Source: Internet
Author: User

The definition of the shell function is almost the same as the normal C language function.

function () {

The return value of the Shell function can be displayed, and if there is no return then the execution result of the last statement will be returned as the return value

The return value of a shell function can only be an integer

Example:

Hello ()

echo "You select Hello"

Hello

Shell function calls are not added ()

Examples of function return values:

Hello ()

{

Return 3

}

Hello

Ret=$?

Echo $ret

Examples of function nesting:

Hello ()

echo "Hello"

World

World ()

{

echo "World"
}

Hello

Examples of function parameters

Hello ()

{

Echo $*

}

Hello 1 2 3 4 5

The shell function must be defined before it can be used, otherwise the error

Function of Shell programming

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.