Let gnome-terminal run bash and tell bash to run your commands and then start a new bash:
$ gnome-terminal -- bash -c "echo foo; echo bar; exec bash"
explanation:
gnome terminal runs bash ...
$ gnome-terminal -- bash -c "echo foo; echo bar; exec bash"
^^^^
which runs your commands ...
$ gnome-terminal -- bash -c "echo foo; echo bar; exec bash"
^^^^^^^^ ^^^^^^^^
and then reexecutes bash.
$ gnome-terminal -- bash -c "echo foo; echo bar; exec bash"
^^^^^^^^^
gnome terminal will not close if something is still running. in this case the second bash is still running. this makes gnome terminal not close and you can interact with bash inside gnome terminal as normal.
exec
is not mandatory here but has some implication which are beneficial for this use case.
if the commands are many or complex you can put them in a script:
$ gnome-terminal -- bash -c "./scripttorun; exec bash"
you can also reexecute bash in the script directly
Prepare scripttobash
:
#!/bin/sh
echo foo
echo bar
exec bash
Then run:
$ gnome-terminal -- ./scripttobash
the advantage is the gnome terminal command became quite simple.
the disadvantage is that the script now always runs a second bash. which means you cannot run the script independently. well maybe you can but the second bash might cause trouble or confusion.
it seems that the bash --rcfile
can be used for this
Prepare somercfile
:
source ~/.bashrc
echo foo
echo bar
Then run:
$ gnome-terminal -- bash --rcfile somercfile
bash will stay open after running somercfile.
i must admit i do not understand completely why --rcfile
has this behaviour but it does.
for completeness
there is an option to keep gnome terminal open after executing the command. but you will not be able to interact anymore. just read the output.
- go to preferences (hamburger button -> preferences)
- go to profiles (i recommend to create a new profile for this case)
- go to command tab
- set "when command exits" to "hold the terminal open"
if you created a new profile you can use it like this:
gnome-terminal --profile=holdopen -- ./scripttorun
Every method has it's quirks. You must choose, but choose wisely.
I like the first solution. it does not need extra files or profiles. and the command says what it does: run commands then run bash again.
All that said, since you used ssh in your example, you might want to take a look at pssh
(parallel ssh). here an article: https://www.cyberciti.biz/cloud-computing/how-to-use-pssh-parallel-ssh-program-on-linux-unix/