In the shell, arguments can be passed to a function when it is called. Inside the function body, the value of the parameter is obtained in the form of a $n, for example, "$" for the first argument, and $ for the second argument
Example:
#!/bin/bash
Funwithparam () {
echo "The first parameter is $!"
echo "The second parameter is $!"
echo "The tenth parameter is $ A!"
echo "Tenth parameter is ${10}!"
echo "11th parameter is ${11}!"
echo "The total number of parameters is $#!"
echo "Output all parameters as a string $*!"
}
Funwithparam 1 2 3 4 5 6 7 8 9 34 73
Output:
The first parameter is 1!
The second parameter is 2!
The tenth parameter is 10!
The tenth parameter is 34!
The 11th parameter is 73!
The total number of parameters is 11!
Output all parameters as a string 1 2 3 4 5 6 7 8 9 34 73!
Note: $ $ cannot get the tenth parameter, and the tenth parameter requires ${10}. When n>=10, you need to use ${n} to get the parameters.
shell--parameter passing