-->
Page 15
* | Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is null or unset, the parameters are separated by spaces. |
@ | Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands as a separate word. That is, "$@" is equivalent to "$1""$2" .... When there are no positional parameters, "$@" and $@ expand to nothing (in other words, they are removed). |
# | Expands to the number of positional parameters in decimal. |
? | Expands to the status of the most recently executed foreground pipeline. |
_ | Expands to the current option flags as specified upon invocation, by the set built-in command, or those set by the shell itself (such as the _i flag). |
$ | Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell. |
! | Expands to the process ID of the most recently executed background (asynchronous) command. |
0 | Expands to the name of the shell or shell script. This is set at shell initialization. If bash is invoked with a file of commands, is set to the name of that file. If bash is started with the _c option, then is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the pathname used to invoke bash, as given by argument zero. |
_ | Expands to the last argument to the previous command, after expansion. Also set to the full pathname of each command executed and placed in the environment exported to that command. |
SHELL VARIABLES
The following variables are set by the shell:
Page 16
HISTCMD | The history number, or index in the history list, of the current command. If HISTCMD is unset, it loses its special properties, even if it is subsequently reset. |
OPTARG | The value of the last option argument processed by the getopts built-in command. (See "Shell Built-in Commands," later in this manual page). |
OPTIND | The index of the next argument to be processed by the getopts built-in command. (See "Shell Built-in Commands.") |
HOSTTYPE | Automatically set to a string that uniquely describes the type of machine on which bash is executing. The default is system-dependent. |
OSTYPE | Automatically set to a string that describes the operating system on which bash is executing. The default is system-dependent. |
The following variables are used by the shell. In some cases, bash assigns a default value to a variable; these cases are noted in the following list:
IFS | The internal field separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. |
PATH | The search path for commands. It is a colon-separated list of directories in which the shell looks for commands. (See "Command Execution," later in this manual page). The default path is system_dependent, and is set by the administrator who installs bash. A common value is /usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin: |
HOME | The home directory of the current user; the default argument for the cd built-in command. |
CDPATH | The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is .:~:/usr. |
ENV | If this parameter is set when bash is executing a shell script, its value is interpreted as a filename containing commands to initialize the shell, as in .bashrc. The value of ENV is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. PATH is not used to search for the resultant pathname. |
If this parameter is set to a filename and the MAILPATH variable is not set, bash informs the user of the arrival of mail in the specified file. | |
MAILCHECK | Specifies how often (in seconds) bash checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before prompting. If this variable is unset, the shell disables mail checking. |
MAILPATH | A colon-separated list of pathnames to be checked for mail. The message to be printed may be specified by separating the pathname from the message with a question mark (?). $_ stands for the name of the current mailfile. |
Example: MAILPATH\ ='/usr/spool/mail/bfox?"You have mail":~/shell-mail?"$_has mail!"'
bash supplies a default value for this variable, but the location of the user mail files that it uses is system-dependent (for example, /usr/spool/mail/$USER). | |
MAIL_WARNING | If set, and a file that bash is checking for mail has been accessed since the last time it was checked, the message "The mail in mail-file has been read" is printed. |
PS1 | The value of this parameter is expanded (see "Prompting," later in this manual page) and used as the primary prompt string. The default value is bash\$. |
PS2 | The value of this parameter is expanded and used as the secondary prompt string. The default is >. |