Nivek Defend Nivek Defend - 1 year ago 117
Bash Question

Close terminal window after using xterm

I have the following code

xterm -e <some command> &
<line 2 command>

Now after the line 2 command I want the close the xterm -e window automated.

How can I close the terminal window that I opened in the my script?


Answer Source

You can simply get PID of the last background task lauched with $!, and then kill it after your line 2 command is achived.

xterm -e <some command>  &
<line 2 command>
kill $myBackgroundXtermPID

I assume that if your background process ends before line 2 , its PID will not be reused by another process (if you run out of PID numbers).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download