Reprint please indicate http://www.cnblogs.com/winifred-tang94/
There are three types of variables in the shell environment:
A, environment variables; You can refer directly to the shell script in the form of "environment variable name".
b, user-defined variables, do not need to be defined in advance, usually, the use of variables to directly assign the initial value. Variable name = variable initial value (Note: Variable name requirement-the first character must be a letter, can be underlined, but cannot have punctuation and spaces, cannot use keywords in the shell)
C, System global variables, representing a specific meaning, can not be modified by the user. In general, the main global variables include the following:
$#: When executing shell scripts, the number of command-line arguments does not include the script itself.
$?: Executes the return value of the previous shell command (exit status, most command execution successfully returns 0, failure returns 1, but there are other commands that return other values to identify other errors).
The name of the $0:shell script program itself. At the same time, $ $ represents the first parameter in the shell command line, and $ $ represents the second argument, and $ $ represents the third argument, and so on.
$*: All parameters passed to the script or function.
$$: The current shell process ID, which is the process ID of the current script.
To use a variable in a script is a method that takes advantage of the "$ variable name".
Eg. Create a script to calculate the sum of two numbers
One notable point : When using expr for operations, remember to add spaces on both sides of the operator.
The result is:
The initial error is as follows:
Cause: This script file requires parameters other than the script itself, and no parameters are entered when the script is run.
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".
Eg.
Use of shell variables