Home >Operation and Maintenance >Linux Operation and Maintenance >How to use $ symbol in linux
There are three ways to use the $ symbol in Linux.
Usage 1:
Display script parameters ($0, $?, $*, $@, $#, $$, $!) (essentially variables replace).
$0: It is the name of the bash file. If it is a single digit, you can use numbers directly. But if it is more than two digits, it must be enclosed by {} symbols, such as ${10}.
$?: It is the return value of the previous command. It is 0 if it is successful and 1 if it is not successful. Generally speaking, the process of UNIX (linux) system ends by executing the system call exit(). This return value is the status value. Passed back to the parent process to check the execution status of the child process. If the general command program is executed successfully, the return value is 0; if it fails, it is 1.
$*: The content of all script parameters: the parameters used to call this bash shell.
Usage 2:
Get the values of variables and environment variables.
For example: path=2, echo $path or echo${path} displays the value of path.
In Linux and Unix sh, the string starting with $ represents the variables defined in sh. These variables can be automatically added by the system, or they can be defined by the user. $PATH represents The system's command search path is the same as Windows' %path%. $HOME represents the user's home directory.
Usage 3:
The difference between $(( )), $( ), `` and ${ } in shell.
Explanation:
${ }This form is actually the same as usage one and two. It belongs to the category of variable substitution, but curly brackets can be added in variable substitution. , or without the braces.
In short: $(( )) belongs to the execution calculation formula, which is equivalent to $[ ], $( ) and ` ` belong to command substitution, and ${ } belongs to variable substitution.
1. $( ) and ``(backtick): Return the result of the command in brackets
In bash, $( ) and ` `(backtick) ) are used for command substitution, executing commands in brackets or backticks.
Command substitution is similar to variable substitution. They are both used to reorganize the command line. First complete the command line in quotation marks, then replace the result, and then reorganize it into a new command line.
2. ${ } variable replacement
Generally, there is no difference between $var and ${var}, but using ${ } will be more accurate. Scope variable names.
Recommended tutorial: linux tutorial
The above is the detailed content of How to use $ symbol in linux. For more information, please follow other related articles on the PHP Chinese website!