1

Whenever I begin a data-manipulation session I have to manually open two terminals - one to work in, and another that runs gnuplot so I can quickly load a plot program to see the results.

Both are opened in the same directory /home/pi/python, where the data is constantly automatically logged and available for analysis.

To minimize typing I have created a script called pj that I've put into /usr/sbin (in my $PATH) that contains

#!/bin/bash
cd /home/pi/python

I invoke it by typing

. pj      (notice the space so when it exits it stays there)

Then I have to click to open a second terminal window where I run a script gp that contains the following commands:

#!/bin/bash
cd /home/pi/python
gnuplot

This one I invoke with

gp   

notice no dot before the command because I don't care what happens when it eventually exits - I tend to leave it open all day.

Is there a way in bash to have one command do both for me?

The question is in the title: can I open two interactive terminal windows in a single script?

Put simply, I would like one command to open two terminal windows into the same subdirectory, with one of them running gnuplot in interactive mode and the other sitting at the bash prompt.

2 Answers 2

1

If you invoke a terminal emulator from the command-line in another terminal emulator, it will (usually) create a new window and then return to the command prompt in the first terminal emulator. Based on that, something along the lines of:

#!/bin/bash
cd python
<whatever-terminal-emulator> --command gnuplot

Should get what you want (although the --command option might be different if you're using a really simple terminal emulator like xterm (for those, you usually just omit the --command option).

3
  • 1
    Maybe not every folder has a subfolder named python?
    – John Goofy
    Jul 24, 2017 at 16:04
  • 1
    It was based on his original scripts, which explicitly cd python. Jul 24, 2017 at 17:01
  • Thank you for pointing me in the right direction, @Austin. I made it work and posted an answer to show what I did. I tried xterm but to make it work I would have had to specify font sizes and stuff - it was way too small. Anyway, I have accepted your answer because you gave me the gold nugget. I hope I can get an upvote so this isn't a zero question. I think this could be useful for a lot of other people. TNX again.
    – SDsolar
    Jul 24, 2017 at 23:16
1

Thanks to @Austin's push in the right direction, here is the script that ended up working.

It is named go and is in my $PATH (/usr/bin on the Ubuntu machines and /usr/sbin on the Raspbian machines), so it works from anywhere:

#!/bin/bash
cd /home/pi/python
gnome-terminal -e gnuplot &
gnome-terminal &

All I have to do is type

go

and it opens the two windows I need.

Interestingly, adding an exit line at the end will not close the original terminal, but that's OK.

This is a time-saver for sure.

1
  • Not just exit fails to do anything but I have also tried kill $PPID and it won't close the parent terminal, either. Not that it matters, it is just curious.
    – SDsolar
    Jul 25, 2017 at 3:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .