/path/to/scriptname opt1 opt2 opt3 opt4 $0 $1 $2 $3 $4
Is that clear enough for you? Run the script file named "$" variable, the first parameter is $ ~ ~ So, as long as we use in script, we can easily release some command function immediately! In addition to the variables of these numbers, we have a few more special variables that can be used within a script to call these parameters Oh!
- $#: On behalf of the following parameters "number", the above table as an example shown here as "4";
- [Email protected]: for "$" "" $ "" $ "" $ "" $4 "meaning, each variable is independent (enclosed in double quotation marks);
- $*: Represents "" "$C$ c$ C $4" ", where C is a delimited byte and the default is a blank key, so in this case, the meaning of" $ $ $4 "is represented in this example.
That [email protected] and $* are basically different! However, the general use of the situation can be directly memory [email protected] can! All right, let's do an example. Let's say I'm going to run a script that can carry parameters, and the screen will display the following data when I run it:
- What is the file name of the program?
- How many parameters are there?
- If the number of parameters is less than 2, it tells the user that the number of parameters is too low
- What are all the parameters?
- What is the first parameter?
- Why the second parameter
Script name sh04. SH
#!/bin/bash# program:# program shows the sripts name, parameters...# history:# -/9/6ZENGDP First Releasepath=/bin:/sbin/:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/Binexport PATHEcho "The script name is ==> $"Echo "Total parameter number is ==> $#"[ "$#"-lt2] && Acho"The number of parameter is less than 2. Stop here."&& exit0Echo "whole parameter is ==> ' [email protected] '"Echo "The 1st parameter ==> $"Echo "The 2nd parameter ==>"
Enter the command sh sh04. SH The one haha quot
After the script is run, output:
The script name is ==> sh06. SH total parameternumber are4whole parameter is ==>'the One haha quot'the1st parameter ==> thethe 2nd parameter ==> one
Shell script already has a variable name configured for the parameter.