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