1

I was wondering if it is possible to sort of restart gnome-terminal from itself? What I mean by that is, is there a command which I can use to tell gnome-terminal to close and then immediately relaunch itself? I have tried running:

exit && gnome-terminal

But that doesn't work because after it has exited it can't launch itself from itself, so I was wondering if there is another command which will close it but also instruct another program to then immediately open it again?


OS Information:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.10
Release:    15.10
Codename:   wily
Flavour: GNOME
GNOME Version: 3.18

Package Information:

gnome-terminal:
  Installed: 3.18.2-1ubuntu2~wily1
  Candidate: 3.18.2-1ubuntu2~wily1
  Version table:
 *** 3.18.2-1ubuntu2~wily1 0
        500 http://ppa.launchpad.net/gnome3-team/gnome3-staging/ubuntu/ wily/main amd64 Packages
        100 /var/lib/dpkg/status
     3.16.2-1ubuntu4 0
        500 http://archive.ubuntu.com/ubuntu/ wily/main amd64 Packages

2 Answers2

6

trap the pseudo-signal EXIT:

trap 'gnome-terminal' EXIT

Now everytime you run exit a new instance of gnome-terminal will be opened by shell and the existing session of shell will be terminated.


As @Byte Commander has pointed out, if you do exit (as you were doing) or press Ctrl + D to exit the shell, the above would create a gnome-terminal window with the same PID as the earlier one (although the shell would get a different PID), this behavior is by design. So to kill the current gnome-terminal process and start a new one, you can do:

trap 'kill $(ps -o ppid= $$) && gnome-terminal' EXIT
heemayl
  • 93,925
4

You need to "detach" newly spawned terminal window. Now what command does that ? nohup or setsid

nohup gnome-terminal && exit

setsid gnome-terminal && exit