Languages

What does mean $$ or $! in Bash?

4 points
Asked by:
Hiba-Tate
548

What is defference beetween $$ and $!?

As I see, both returns some number.

1 answer
6 points
Answered by:
Hiba-Tate
548

$$ returns currently run process ID (PID)

#!/bin/bash

pid=$$

echo "Current script PID: $pid"

 

$! returns last program PID that your shell ran in the background (e.g. command &)

#!/bin/bash

sleep 5 &
pid=$!

echo "sleep command PID: $pid"
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join