1. Shell function: The shell allows a set of command sets or statements to form an available block called a shell function.
A function consists of two parts: a function title, a function body.
The title is the function name. A function body is a collection of commands within a function.
The title name should be unique, and if not, the result will be confused because the script will first search for a function to call the appropriate shell before viewing the calling script.
2, the format of the definition function is:
Function name () {
Command 1
...
}
If you prefer, you can precede the function name with a keyword function, depending on the user.
function functions name ()
{
Command 1
...
}
3, for example:
Example 1: Deleting a blank line in a file
This script (del.lines) can process one or more files. Each file must verify existence before using SED to delete empty lines.
The output of SED is imported into a temporary file with $ $ in the filename, and finally the temporary file is moved back to the original file.
The script uses the shift command to get all the file names and process all the files with the while loop until the process is complete
So far. You can use Del.lines--help to get a short help
Add Execute permissions to script files after saving: chmod +x del.lines
To execute a script for testing: