Special variables
$ A: The file name of the current script
$num: Num is a number starting from 1, and $ is the first argument, and $ is the second argument, ${10} is the tenth argument
$#: Number of arguments passed in the script
$*: All positional parameters (as a single string)
[Email protected]: all positional parameters (each as a separate string).
$?: The return value of the previous command in the current shell process, if the previous command succeeds, the value of $ is 0, otherwise a value other than 0 is commonly used to make an if statement condition
$$: pid of the current shell process
$!: PID of the last process running in the background
$-: Shows the current options used by the shell
$_: Last parameter of previous command
The role of SET-E
Every script you write should include Set-e at the top. This tells bash, it should exit the script if any statement returns a non-true return value. The benefit of USING-E is that it prevents errors snowballing to serious issues when they could has been caught Earlie R. Again, for readability-want to use Set-o errexit.
Each script you write should be prefixed with SET-E at the beginning of the file, which tells Bash to exit if the execution of any statement is not true. The upside is to prevent mistakes from snowball-like to cause a fatal error that should have been dealt with before. If you want to increase readability, you can use Set-o Errexit, which works the same as SET-E.
USING-E gives you error checking for free. If you forget to check something, bash would do it for you. Unfortunately it means you can ' t check $? As bash would never get to the checking code if it isn ' t zero. There is other constructs your could use:
Use-e to help you check for errors. If you forget to check (execute the result of the statement), Bash will do it for you. Unfortunately, you will not be able to check $? Because if the executed statement is not returned 0,bash will not be able to execute into the checked code. You can use other structures:
Shell Learning Notes