APPENDIX B
Special Parameters

Shell special parameters are variables internal to the shell. These variables reference various items, such as the parameters passed to a script or function, process IDs, and return codes. It is not possible to assign a value to them since they can only be referenced.

This appendix is a compilation of the parameters available in bash, ksh, pdksh, and Bourne sh. All of these variables are accessible in each of the shells mentioned, except for $_, which is not available in the Bourne shell.

It isn't necessarily obvious from the shell man pages that you would need to prepend the variables with a $ sign to reference them. For instance, to find the value of the previous command's return code, you would use a command like this:

echo $?

or

RETURN_CODE=$? ; echo $RETURN_CODE

Table B-1. Shell Internal Special Parameters

Parameter Definition
* Complete list of all positional parameters, starting at 1. If double quoted, becomes a single word delimited by the first character of the IFS (internal field separator) value.
@ Complete list of all positional parameters, starting at 1. If double quoted, becomes individual words for each positional parameter.
# The number of positional parameters, in decimal.
? The return code from the last foregrounded job. If the job is killed by a signal, the return code is 128 plus the value of the signal. Example: Standard kill is signal 15, which would result in a return code of 143.
- All of the flags sent to the shell or provided by the set command.
$ The shell's process ID. If in a subshell, this expands to the value of the current shell, not the subshell.
! The process ID of the most recently backgrounded command.
_ Expands to the last argument of the previous command.
0 Expands to the name of the shell or shell script.
1...9 The positional parameters provided to the shell, function, or script. Values larger than 9 can be accessed with ${number}.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.58.155