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?


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.

  • 1
    How do you get the PID of the subshell? – trysis May 11 '15 at 2:42
  • 3
    @trysis In bash > 4, the subshell's PID (as any shell's PID) is stored in $BASHPID – kos May 11 '15 at 4:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.