Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close gnome-terminal with specific title from another script/shell command

Tags:

linux

bash

shell

I need to close a specific gnome-terminal window having a unique name from any other bash/shell script.

Eg:

$] gnome-terminal --title "myWindow123" -x "watch ls /tmp"

...
...

gnome-terminal opened in the name "myWindow123"

All I need is to kill that terminal from my script. Is there expect kind of script support in bash also?

like image 607
Ashwin Avatar asked Dec 18 '25 01:12

Ashwin


1 Answers

As a contestant for the ugliest hack of the day:

sh$ TERMPID=$(ps -ef |
              grep gnome-terminal | grep myWindow123 |
              head -1 | awk '{ print $2 }')
sh$ kill $TERMPID

A probably better alternative would be to record the PID of the terminal at launch time, and then kill by that pid:

sh$ gnome-terminal --title "myWindow123" -x "watch ls /tmp"
sh$ echo $! > /path/to/my.term.pid

...
...
# Later, in a terminal far, far away
sh$ kill `cat /path/to/my.term.pid`
like image 140
Sylvain Leroux Avatar answered Dec 20 '25 16:12

Sylvain Leroux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!