Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does mean $$ or $! in bash? [closed]

Tags:

bash

shell

It's kind of easy question but I didn't find any information. What does mean $! or $$ in bash?

For example: ps -p $! or pstree $$?

like image 769
NGix Avatar asked Dec 02 '12 17:12

NGix


People also ask

What is $$ in script?

The $$ variable is the PID (Process IDentifier) of the currently running shell. This can be useful for creating temporary files, such as /tmp/my-script. $$ which is useful if many instances of the script could be run at the same time, and they all need their own temporary files.

What does $$ mean in shell?

$$ is the pid (process id) of the shell interpreter running your script. It's different for each process running on a system at the moment, but over time the pid wraps around, and after you exit there will be another process with same pid eventually.As long as you're running, the pid is unique to you.

What is Echo $$ in bash?

The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.

What is the difference between $$ and $! In Linux?

$$ gives the process id of the currently executing process whereas $! Shows the process id of the process that recently went into the background.


1 Answers

Actually, these variables were inherited by bash from the Bourne shell.

$$ means current PID.

$! is the PID of the last program your shell ran in the background (e.g. myprog &)

Here is a list of shell variables:

  • http://unixhelp.ed.ac.uk/scrpt/scrpt2.2.2.html
like image 59
paulsm4 Avatar answered Sep 21 '22 06:09

paulsm4