Shell Programming Learning: Shell subroutine structure and functions

Source: Internet
Author: User
Tags exit exit in

Functions simplify code and enable scripting code reuse. One definition can be invoked more than once. Structured programming to enhance readability, you can define functionality as multiple functions, then save it in a file, and then use Source (.) in ~/BASHRC or at the command line. Call this file. Speed up the operation

1. Methods of defining functions (traditional style)

function name{
                                                                                                  
}

C Language Style:

Name () {
}

It is recommended to use C language style, good compatibility, can be used in Csh/tsch

The difference between return and exit in a function, returning exits execution, returns to the main program function, and continues execution

Exit exits the current script directly.

The role of shift in the shell, like assigning a $ to $1,$3 assignment to $2,$4 to $

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

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.