Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

#!/bin/bash 

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

script.sh

#!/bin/bash 
PID= $$

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

REGARDS

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

1 Answer 1

up vote 1 down vote accepted

You can get print the PID by doing this

the main script

#!/bin/bash 

gnome-terminal -e "/home/......./script.sh" &
PID=$!
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/..../script.sh run it directly without gnome-terminal:

#!/bin/bash 

/home/......./script.sh &
PID=$!
echo "child_PID="$PID

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

EDIT: The script.sh 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

 
discard

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.