How to execute more than one command in a newly opened terminal?

I have a script that I want to use to open new terminals and type commands in them. A command like


opens a new terminal.

Also, if I do

gnome-terminal -e myprogram1

it will execute myprogram1 in the newly opened terminal. But what if, after myprogram1 completes, I want to execute myprogram2? I cannot do something like

gnome-terminal -e myprogram2

because it will open a new terminal.

Is there a way to specify in the script that I want to execute both myprogram1 and myprogram 2 in the same new terminal? Or would I have to create a new script and do something like

gnome-terminal -e scriptToExecuteMyPrograms1And2


You can accomplish what you want like this:

$ gnome-terminal -e "bash -c '<cmd1>;<cmd2>;exec $SHELL'"

This will open up <cmd1>, when that’s complete, it will open up <cmd2>, finally it will leave you at a command prompt exec $SHELL.

For example:

$ gnome-terminal -e "bash -c 'vim;vim;exec $SHELL'"

Runs vim, if I close the 1st vim, a 2nd vim is started. When the 2nd one closes I’m left at a terminal prompt.

Leave a Reply

Your email address will not be published. Required fields are marked *