How to get the PID of my script?

If I have the script "script1.sh" and I want to make it print its own PID as a first step. How can I do this in bash?


Solution 1:

The PID of the currently running script is $$

http://www.gnu.org/software/bash/manual/bashref.html#index-_0024_0024

($$) Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell.