1

I know how to create and kill a gnome-terminal using the regular old line for creating a terminal and then just hitting exit. how do I assign a terminal to a variable so I can do like TERMINEL_1 = gnome-terminal... and then do $(TERMINAL_1) to open that terminal. After how would I also kill this particular terminal using that variable? this is all in bash by the way.

  • Actually I really don't see how this question is related to the one pointed. The OP is asking about invoking and killing a terminal using a variable. – terence hill Jan 22 '16 at 13:27

1 Answers1

0

You do not assign a terminal to a variable. You can get the pid of the launched process and assign it to a variable. In bash the pid of the last execute process is $!

The following script lauch a terminal and after 2 seconds kill it. I used xterm but any terminal is good.

#!/bin/bash

xterm &

pid="$!"
echo "$pid"
sleep 2

kill "$pid"

If you want to run a command in the new terminal you can use:

xterm -hold -e command &

For gnome-terminal the syntax is just:

gnome-terminal   -e "command" & 

For further information on launch commands in the new opened terminal see this post

Community
  • 1
  • 1
terence hill
  • 3,354
  • 18
  • 31
  • 1
    Do NOT use SIGKILL (kill -9) to terminate processes. All processes will terminate in response to the default SIGTERM. If they don't terminate instantly, that's because they're busy cleaning up. If you interrupt them, you break them. See http://stackoverflow.com/a/690631/347411 – Rany Albeg Wein Jan 22 '16 at 00:21