Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a script which is the main one and this script open a new terminal and execute another script so what i want is to pass the PID of the second script to the first script

the main script


gnome-terminal -e "/home/......./"

PID= $$

i want to pass the variable called PID to the main script


share|improve this question
beware, in shell variable assignment, you must not put spaces around the "=". – glenn jackman May 4 '13 at 21:34
thank u ı wıll consıder that – Ahmed Zain El Dein May 4 '13 at 22:12
up vote 1 down vote accepted

You can get print the PID by doing this

the main script


gnome-terminal -e "/home/......./" &
echo "child_PID="$PID

Note that you will may get the PID of the gnome-terminal and not the script itself.

If you want the PID of the /home/..../ run it directly without gnome-terminal:


/home/......./ &
echo "child_PID="$PID

A question: Do you really need to run the script through gnome-terminal?

EDIT: The now runs in background ( with & ) and we're echoing the child PID.

share|improve this answer
yes i do actually i had too :) – Ahmed Zain El Dein May 4 '13 at 18:35
it doesnt work with me thank u anyway – Ahmed Zain El Dein May 4 '13 at 18:41
did u try it urself ? – Ahmed Zain El Dein May 4 '13 at 18:55
Yes, I tried it myself. Maybe you are missing and echo on PID or what you really want is that the process runs in background (&). I'll update the answer to make those clear. – Onilton Maciel May 5 '13 at 19:03
thank u sir :-) – Ahmed Zain El Dein May 5 '13 at 19:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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