I. Basics
We define a variable (there cannot be spaces on both sides of the equal sign)
Filepath =/var/home/SSS
Filefilename = test001
When referencing this variable, we can directly use the variable name following $.
For example, $ filepath
You can also: $ {filepath}
The advantage of using $ {} Is that the connection between the two variables can be easily realized, and it is clear at the same time.
$ {Filepath}/$ {filefilename}
This will indicate the full path of the file.
---------------------------------------------
2. Sometimes we see
$1, $2, which indicates the parameters passed in during shell execution.
-------------------------------------------
3. We will also see the following forms
1. If the variable meter has a value or is empty, use the value of value.
$ {Variable:-value}
2. If the variable meter has a value or is empty, use the value of value and assign the variable value to value.
$ {Variable: = value}
3. Check whether the variable is empty.
$ {Variable :?}
------------------------------------------
Which of the following are not commonly used?
--------------------------------------------
$0 shell command itself (including the full path)
$1 to $9 indicates the shell Parameters
$ # Number of parameters passed to the script
$ * Display all parameters passed to the script with a single string
$ ID of the script run
$! ID of the last process running in the background
$ @ Is the same as $.
$-Display the current options used by shell.
$? Displays the execution status of the last command. 0 indicates no error.