List of special variables
variables |
meaning |
$ |
File name of the current script |
$n |
Arguments passed to the script or function. N is a number that represents the first few parameters. For example, the first parameter is $ $, and the second argument is $ A. |
$# |
The number of arguments passed to the script or function. |
$* |
All parameters passed to the script or function. |
[Email protected] |
All parameters passed to the script or function. When enclosed by double quotation marks (""), it is slightly different from $*. |
$? |
The exit state of the last command, or the return value of the function. |
$$ |
The current shell process ID. For Shell scripts, this is the process ID where the scripts are located. |
$* and [email protected] All represent all parameters passed to a function or script, and are not enclosed by double quotation marks (""), with "$" and "$" ... All parameters are output in the form "$n".
But when they are enclosed in double quotation marks (""), "$*" takes all the parameters as a whole and outputs all parameters in the form of "$ $ ... $n"; "[email protected]" separates the various parameters to "$" "$" ... All parameters are output in the form "$n".
The following example can clearly see the difference between $* and [email protected]:
Execute./test.sh "a" "B" "C" "D" and see the following result:
$*= a b c d "$*" = a b c d[email protected]= a b c d "[email protected]" = a b c dprint each param from $*abcdprint ea CH param from [e-mail protected]abcdprint each param from ' $* ' a b c dprint each param from "[email protected]" ABCD
Exit status
$? You can get the exit status of the previous command. The so-called exit status is the return result after the last command was executed.
Exit status is a number, in general, most of the command execution succeeds returns 0, and the failure returns 1.
However, there are some commands that return other values that represent different types of errors.
In the following example, the command executes successfully:
$./test.sh Zara alifile Name:./test.shfirst parameter:zarasecond parameter:aliquoted Values:zara AliQuoted Values: Zara alitotal number of Parameters:2$echo $?0
-e filename true if filename exists
-d filename If filename is a directory, true
-F filename True if filename is a regular file
-L filename True if filename is a symbolic link
-r filename If filename is readable, true
-W filename if filename is writable, true
-x filename If filename is executable, true
-S filename true if the length of the file is not 0
-H filename True if the file is a soft link
Filename1-nt filename2 If filename1 is newer than filename2, it is true.
Filename1-ot filename2 If filename1 is older than filename2, it is true.
-eq equals
-ne Not equal to
-GT Greater than
-ge greater than or equal to
-lt less than
-le less than or equal to
As for the number, that is to take the non-Bai!
Shell Special variables