Special shell Variables

Source: Internet
Author: User

Man Bash:

Special Parameters
The shell treats several parameters specially. These parameters may
Only be referenced; assignment to them is not allowed.
* Expands to the positional parameters, starting from one. When
The expansion occurs within double quotes, it expands to a sin ‐
GLE word with the value of each parameter separated by the first
Character of the IFS special variable. That is, "$ *" is equiva ‐
Lent to "$ 1C $ 2C...", where C is the first character of the value
Of the IFS Variable. If ifs is unset, the parameters are sepa ‐
Rated by spaces. If ifs is null, the parameters are joined
Without intervening separators.
@ Expands to the positional parameters, starting from one. When
The expansion occurs within double quotes, each parameter
Expands to a separate word. That is, "[email protected]" is equivalent to "$1"
"$2"... if the double-quoted expansion occurs within a word,
The expansion of the first parameter is joined with the begin ‐
Ning part of the original word, and the expansion of the last
Parameter is joined with the last part of the original word.
When there are no positional parameters, "[email protected]" And [email protected] expand
Nothing (I. e., they are removed ).
# Expands to the number of positional parameters in decimal.
? Expands to the exit Status of the most recently executed fore ‐
Ground pipeline.
-Expands to the current option flags as specified upon invoca ‐
Tion, by the set builtin command, or those set by the Shell
Itself (such as the-I option ).
$ Expands to the process ID of the shell. In a () subshell, it
Expands to the process ID of the Current Shell, not the sub ‐
Shell.
! Expands to the process ID of the most recently executed back ‐
Ground (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 com ‐
Mands, $0 is set to the name of that file. If Bash is started
With the-C option, then $0 is set to the first argument after
The string to be executed, if one is present. Otherwise, it is
Set to the file name used to invoke bash, as given by argument
Zero.
_ At Shell startup, set to the absolute pathname used to invoke
The shell or shell script being executed as passed in the envi ‐
Ronment or argument list. Subsequently, expands to the last
Argument to the previous command, after expansion. Also set
The full pathname used to invoke each command executed and
Placed in the Environment exported to that command. When check ‐
Ing mail, this parameter holds the name of the mail file cur ‐
Rently being checked.

 

 

Http://blog.sina.com.cn/s/blog_6739945f0100sosu.html

Special shell variables:

$0 get the name of the currently executed shell script

$ N obtain the nth parameter value of the currently executed shell script, n = 1 .. 9

$ * Get all parameters of the current shell "$1 $2 $3 ..., Controlled by IFS

$ # Obtain the total number of parameters in the Current Shell Command Line

$ Obtain the current shell process ID (PID)

$! PID used to execute the previous command

$? Obtain the returned value of the previous Command executed (0 indicates success, and non-zero indicates failure)

[Email protected] All parameters of this program "$1" "$2" "$3" "…", Not controlled by IFS

Note:

Ifs: IFS (internal field seperator) delimiter preset in Linux Shell, used to break down command line into word (field ). Ifs can be one or several of white space, tab, and enter.

The differences between [email protected] and $ * are as follows:
The main difference between the two parameters is that they have different extension parameters. When $ * is used, each parameter is simply extended without retaining the reference. This causes a problem: when there is a space in the parameter, this parameter is identified as multiple parameters, for example, mytar-T "My tarfile.tar". When $ * is used, it will be identified as my‑tarw.file.tar files, [email protected] is used to identify a file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.