Code: Script_name parameter1 parameter2 Parameter3 ...
It's easy to guess that the $ A is the shell script name (path) itself, and $ $ is the first argument, and so on ....
you have to pay attention to the role of IFS, that is, if IFS is quoting, then Positionalparameter will change.
The following example:
code: my.sh P1 "P2 p3" p4
Fucntion, I didn't say it was script in script
< Span style= "color: #008000;" The exception is $ A.
For example: There is a fucntion called My_fun in my.sh, if you run My_fun FP1 fp2 in script, FP3 pan>
Then, the function of the $ is my.sh, and that is FP1 rather than P1 ...
code: #!/bin/ Bash
My_fun () {
Echo ' $ inside function is ' $
Echo ' inside function is ' $
Echo ' $ inside function is ' $
}
Echo ' $ outside function is ' $
Echo ' outside function is ' $
Echo ' $ outside function is ' $
My_fun FP1 "FP2 fp3"
Then run the script in command line to find out:
Code: chmod +x my.sh./my.sh p1 "P2 p3"
$ outside function is./my.sh
$ outside function is P1
$ outside function is P2 p3
$ inside function is./my.sh
$ inside function is FP1
$ inside function is FP2 FP3
We often use the following method in the shell script to test if the script has read parameters:
Code:
if [$# = 0] //See not, all the contents of [] must have spaces in parentheses
If it is 0, it means that the script does not have a reference, or that it has a number of parameters ...
In the shell, we can use $ A, $, $, $ ... This variable extracts the variables in the command line