0

I want to write piece of bash script that open a gnome-terminal tab and execute some commands in it after finishing execution terminal will close , i would like the make bash recognize if this terminal is closed or still open cause i will make some action if it has been closed and make my script waits if it is still opened

can anyone help ?

4

You can run gnome-terminal disabling the factory mode. This will prevent it from starting a terminal connected to an existing terminal, so that the command does not return immediately:

gnome-terminal --disable-factory
echo Done. # Will only run after the terminal opened above has been closed

From man gnome-terminal:

--disable-factory
             Do not register with the activation name server, do  not  re-
             use an active terminal.

Most applications start a new process independent of any previously running processes when run. Some applications (like Firefox, GNOME Terminal, etc.) do not open a completely new process when run. They start a session tied to an existing process. So if you have a Firefox window open, and you run:

firefox

in a terminal, it will open a new window connected to the existing process and return immediately. In the case of GNOME Terminal, you can disable this behaviour using the above option. With --disable-factory, the new window opened is tied to this command, so the command waits until the window is closed.

  • it works fine and great but i don't understand how actually , i will appreciate it so much if u explain more pls :) – Ahmed Zain El Dein Sep 16 '14 at 15:05
  • @AhmedZainElDein updated with an explanation. – muru Sep 16 '14 at 15:11
  • When u say "so the command waits until the window is closed." ,so if i wrote those command that will be execute in terminal in for loop that means like this : for (( ; ; )) do gnome-terminal -- disable-factory line 1 gnome-terminal -- disable-factory line 2 done he will not execute line line2 until line1 is closed? – Ahmed Zain El Dein Sep 16 '14 at 15:21
  • @AhmedZainElDein yes, the second gnome-terminal will not be executed until the first is ended. – muru Sep 16 '14 at 16:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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