Special Parameters
Parameters: $?
The exit code of the previous command or script, 0 for success, non-0 for failure.
Will output 2, indicating failure. The return code can be specified in scripts using exit
.
Parameters: $#
Indicates the number of arguments passed to the script or function.
Parameters: $*
All arguments passed to the script, separated by spaces by default.
The separator can be modified through the IFS
variable.
Parameters: $@
All arguments passed to the script, separated by spaces by default.
The separator can be modified through the IFS
variable.
Difference: $* vs $@
The main difference lies in handling arguments with spaces.
$*
: Represents all arguments as a single string, a whole.$@
:- Without double quotes: Same as
$*
. - With double quotes:
"$@"
, represents an array of arguments, each argument is independent.
- Without double quotes: Same as
Parameters: $$
The process ID of the current script.
Parameters: $!
The process ID of the most recently backgrounded process.
Parameters: $0
The name of the current script.
Parameters: $n
The nth argument.
Parameters: $-
The options of the script.
Above are the startup options of the current Shell.