Home > Operation and Maintenance > Linux Operation and Maintenance > What does $$ mean in Linux shell?

What does $$ mean in Linux shell?

WBOY
Release: 2022-03-04 11:59:06
Original
15261 people have browsed it

In Linux, the shell is a command line interpreter. "$$" means the PID of the current shell, which is the current process number of the script running; the function of the shell is to interpret the entered command and Passed to the system, it provides users with a program to send requests to Linux.

What does $$ mean in Linux shell?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What does $$ mean in Linux shell

Shell is a command line interpreter. Its function is to follow a certain grammar to interpret the input commands and pass them to the system. It provides users with an interface system-level program that sends requests to Linux to run programs. Users can use Shell to start, suspend, stop, and even write some programs.

$$ The PID of the current shell (that is, the current process number where the script is running)

Shell itself is the bridge for users to use Linux. Shell is both a command language and a programming language (what you call a shell script). As a command language, it interactively interprets and executes commands entered by the user; as a programming language, it defines various variables and parameters, and provides many control structures found only in high-level languages, including loops and branches.

Although it is not part of the Linux system kernel, it calls most of the functions of the system kernel to execute programs, create files, and coordinate the running of various programs in a parallel manner.

Knowledge expansion:

$0 The execution name of the current script

$n The nth parameter value of the current script execution command, n = 1..9

$* All parameters of the current script execution command. This option parameter can exceed 9

$# The number of input parameters of the current script execution command. For example, if ./test.sh aa bb cc is executed, then in $# in test.sh is 3

$! The PID of the last executed command (the process ID number of the last process running in the background)

$- displays the current options used by the shell, and The set command has the same function

$@ Similar to $*, but can be used as an array

$? The return value of the previous execution command (displays the exit status of the last command, 0 means no error , any other value indicates an error), as shown below

# 结果输出上一条命令 grep 命令的返回值
grep xxx a.txt
echo $?
 
# 判断打开目录命令是否成功,不成功则输出提醒信息并退出
dir_exe=../cron
cd $dir_exe
if [ $? -ne 0 ]; then 
    echo "cannot change dir to $dir_exe"
    exit 1  
fi
Copy after login

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What does $$ mean in Linux shell?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template