$ represents the ID of the current shell process, which is the PID
$echo $$
Run results
2934
List of special variables
variables |
meaning |
$0 |
filename of the current script |
|
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. |
Command-line arguments
#!/bin/BashEcho "File Name: $"Echo "First Parameter: $"Echo "First Parameter: $"Echo "Quoted Values: [email protected]"Echo "Quoted Values: $*"Echo "total number of Parameters: $#"
Operation Result:
$./test. SH Zara alifile Name:. /test. SH 2
The difference between $* and [email protected]
$* 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".
#!/bin/BashEcho "\$*="$*Echo "\"\$*\"=" "$*"Echo "\[email protected]="[email protected]Echo "\ "\[email protected]\" =" "[email protected]"Echo "print each param from \$*" forVarinch$* Do Echo "$var" DoneEcho "print each param from \[email protected]" forVarinch[email protected] Do Echo "$var" DoneEcho "print each param from \ "\$*\"" forVarinch "$*" Do Echo "$var" DoneEcho "print each param from \ "\[email protected]\"" forVarinch "[email protected]" Do Echo "$var" Done
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 $*"$* " "[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.
$./test. SH Zara alifile Name:. /test. SH 2$echo $? 0 $
Shell Special variables