directory

 

Introduction to the

Parameters of the variable

The return command

Global and local variables, local command


Introduction to the

Functions are snippets of code that can be used over and over again. It differs from aliases in that aliases are suitable for encapsulating simple single commands, whereas functions can encapsulate complex multi-line commands.

Functions are always executed in the current Shell. This is a major difference from scripts. Bash creates a new subshell to execute the script. If the function has the same name as the script, the function is executed first. However, functions take precedence over aliases, that is, if the function has the same name as the alias, the alias takes precedence.

There are two syntax definitions for Bash functions.

# the first
Copy the code