$ represents the current process when using the Echo $$ is the PID that will output the current shell
1 Echo $$
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 $*, as will be mentioned below. |
$? |
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. |
Script File varlist.sh
1#!/bin/Bash2 3 Echo "File Name: $"4 Echo "First parameter: $"5 Echo "Second Parameter: $"6 Echo "Quoted Values: [email protected]"7 Echo "Quoted Values: $*"8 Echo "total number of Parameter: $#"
Execute the varlist.sh Hello World result output as follows:
$ sh./varlist.sh Hello worldfile name:./varlist.shfirst parameter:hellosecond parameter:worldquoted Values:hello worl dquoted Values:hello worldtotal Number of Parameter:2
The difference between $* and [email protected]:
When using "" is going out for them difference, "$*" will all the parameters as a whole, in the form of "$ $ ... $n" Output all parameters, "[email protected]" will separate the various parameters to "$" "$" ... All parameters are output in the form "$n". Look at the following example:
1#!/bin/Bash2 #description: Use variable3 #Author: Blacksonny4 #Copyright (c)5 #Script follows here:6 7 Echo "\$*="$*8 Echo "\"\$*\"=" "$*"9 Ten Echo "\[email protected]="[email protected] One Echo "\ "\[email protected]\" =" "[email protected]" A - Echo "print each param from \$*" - forVarinch$* the Do - Echo "$var" - Done - + Echo "print each param from \[email protected]" - forVarinch[email protected] + Do A Echo "$var" at Done - - Echo "print each param from \ "\$*\"" - forVarinch "$*" - Do - Echo "$var" in Done - to Echo "print each param from \ "\[email protected]\"" + forVarinch "[email protected]" - Do the Echo "$var" * Done
Output Result:
1$ sh./varcompare.sh"a" "b" "C" "D"2$*=a b c D3 "$*"=a b c D4[Email protected]=a b c D5 "[email protected]"=a b c D6Print eachparamFrom $*7 a8 b9 CTen D OnePrint eachparamFrom [email protected] A a - b - C the D -Print eachparamFrom"$*" - a b c D -Print eachparamFrom"[email protected]" + a - b + C AD
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.
Special variables in the shell