2.Linux Shell function

Source: Internet
Author: User

Order of 1.Shell Search commands

When the shell executes the command, it does not directly look in the path path, but instead looks for the command location in a fixed order. The search order is as follows.

1. Aliases. Even if you create a command with alias commond= "...".

2. Keywords. such as If,for.

3. function.

4. Built-in commands. such as Cd,pwd and other orders.

5. External commands. Script or executable program, which is only found in path paths.

2. Rules used by functions

1. Define first, then use.

2. The function runs in the current environment and shares the variables in his script.

3. Functions allow parameters to be passed as positional parameters, positional parameters are private to the function, and any action on positional parameters does not affect any parameters used outside the function.

4. Inside the function, local variables are created using local qualifiers.

5. If the function uses the Exit command, it exits the script.

6. function return using return. If you do not specify a parameter for return, the function returns the exit state of the last command. The return command can also return the arguments passed to it, and as a rule, the return command can return only integers between 0~255.

7. Use the built-in command export-f to export the function to a child shell.

8. If the function is saved in another file, you can use the source or dot command to load them into the current script.

3. Function definition

To define a function, you can use the following two forms:

function funcname ()        #在这种情况下, parentheses are not required {    Shell commands}

Or

FuncName () {    Shell commands}

There is no functional difference between the two. Just like deleting a variable, a function can also be deleted by Unset-f funcname. Where the-f parameter prompts the unset command to remove the function.

  

2.Linux Shell function

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.