I have a script in a gnome-terminal shell and I would like to open a new terminal, load the bashrc configuration, execute a new script and avoid the closure of the new terminal window.

I have tried to execute this commands:

gnome-terminal -x bash

the script above open a new shell and loads bashrc, but I don't know how to execute a script automatically.

gnome-terminal -x ./new_script.sh

the script above open a new shell and execute the script but doesn't load bashrc and close the window.

The result that I would like to obtain is to feel like opening a new terminal as clicking the term icon but execute a script after the bashrc setup.

2 Answers 2

gnome-terminal -e command


xterm -e command


konsole -e command

Pretty much

terminal -e command

To make the terminal stay when the command exits:

In konsole there is a --noclose flag.

In xterm, there is a -hold flag.

In gnome-terminal, go to Edit -> Profile Preferences -> Title. Click the Command tab. Select Hold the terminal from the drop-down menu labelled When command exits. You should create a new profile for that and execute with

gnome-terminal --window-with-profile=NAMEOFTHEPROFILE -e command
  • Thanks! But I don't see the bashrc output when I run gnome-terminal -e ./new_script.sh --window-with-profile=my_profile. Have I forgotten something?
    – Cyr
    Commented Jan 31, 2017 at 11:32

You could create a wrapper script that basically looked like this:

#!/bin/bash -i

And then run [terminal] -e wrapper-script.sh.

The -i flag in the shebang will make the wrapper script run in interactive mode, so it will load .bashrc; then it will run new-script.sh, and then it'll start a new bash instance so you can run whatever commands you want afterwards in that instance.

(Or you can put the -i flag on the shebang of the ./new-script.sh if wanted it always to do that.)

If you don't want to be able to run commands afterwards, but just want the terminal to hold open, then you can leave out the second bash and use whatever flag or setting or profile is appropriate for doing that depending on the terminal.


You must log in to answer this question.

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