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?

1 Answer

The PID of the currently running script is $$

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

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like