Ubuntu – How to write a shell script that runs commands in separate terminals

bashcommand linescripts

I've never written a script before, and I need help with my first one.

I have 3 commands, that need to run in order, in separate windows.

How do i write a script that I can execute, that runs command one, command two, and command three, in order, in separate windows?

I have tried making sense out of other posts, but haven't had any luck

Best Answer

You can do it just by calling three instances of your terminal emulator and telling them to stay open with exec bash


mate-terminal -x bash -c 'uname -r; exec bash'
mate-terminal -x bash -c 'uname -m; exec bash'
mate-terminal -x bash -c 'uname -s; exec bash'

The first terminal pops up with 4.4.0-42-generic second one with x86_64, third one with Linux...

If you're using vanilla Ubuntu, then replace mate-terminal with gnome-terminal or whatever app you use. Replace uname -[rms] with your commands. You may find you need to use -e and not -x for gnome-terminal.

Help from this answer posted by Chaos