Linux scripts are huge and powerful.
Definition:
Function Name () // function can be omitted
{
Command
}
Call: directly use the function name in the script. Of course, you can also include parameters such
Function Name parameters (separated by spaces)
Passing parameters to a function: Like using parameters in a general script, the original parameters are returned to the shell script after obtaining parameters using the special variable $1 $2... $9. It can be understood as a C function stack call.
Function Exit:
Commonly used exit methods of scripts include exit 0 (normal exit of the table) and Exit 1 (indicating an error exits)
The return 0 and return 1 functions are returned, but the return state is determined by the last instruction of the function.
Below is a small experiment script written by myself.
#! /Bin/bash
Try ()
{
While [$ #-GT 0]
# Until [$ #-LT 1] // both statements can be used. Note that the test statement is written in [Space]; otherwise, an error occurs.
Do
Echo $1
Shift
Done
}
Try I am a student
Echo $1
The running result is as follows:
ThinkPad @ thinkpad-ThinkPad-R400:/Media/personal/Ubuntu $./fff hello
I
AM
A
Student
Hello
Thinktablet @ thinkpad-ThinkPad-R400:/Media/personal/Ubuntu $