I'm working in a remote server that uses Scientific Linux (version=7.6 (Nitrogen)). I did a simple web application in Python3, and I found myself constantly opening a Mate Terminal (though, any terminal works), and writing

python3 my_app.py

So, I can check if my app works locally in my browser.

I want a way to make this easier, and just click a shell script that opens a terminal windows and runs the commands mentioned. After that, the terminal window should remain open and I should be able to check my web application in the browser.

I wrote a shell script with this line:

gnome-terminal --tab --title="tab 1" --command="bash -c 'python3 my_app.py; $SHELL'"

As recommended here, in the case of Ubuntu: https://askubuntu.com/questions/46627/how-can-i-make-a-script-that-opens-terminal-windows-and-executes-commands-in-the (Note: I tried all other answers and they didn't work, Gabriel Staples answer was the only one that almost worked). I also allowed the file to be executed as program.

There are 2 problems with this solution. First, the terminal does not remain open. Second, when I click the file I received the following message (before terminal is closed): ModuleNotFoundError: No module named 'flask'. This is because the script is using the wrong version of python3 in this server. There is one installed by the admin, and the anaconda version installed by me in my home directory. I've been getting around this problem by writing bash before using python3 my_app.py. It seems that after I use bash the file .bashrc in my home directory is used, and the variable $PATH gives priority to my version of python3 (I checked that $PATH is different before and after I write bash in the terminal).

I was wondering if there is a way to make a script (on Scientific Linux) that opens a terminal window and executes commands in them, and after that remains open.

I also was wondering if there is a way that the web application automatically pops up in my browser after this.

  • xterm -hold -e yourcommands <- if you permit using another terminal instead of gnome-terminal
    – francois P
    Jun 5, 2019 at 18:24
  • or look into screen or tmux rather than a GUI terminal window.
    – DopeGhoti
    Jun 5, 2019 at 18:51
  • Gabriel Staples here. My other answer is now obsolete, but give this one a try instead. I've massively rewritten it and tested it on Ubuntu 18 and now use this approach today: askubuntu.com/questions/315408/…. Feb 17, 2020 at 18:22

1 Answer 1


The terminal will close after the command is completed. To leave the terminal open, I generally prevent the script from completing, e.g. with a prompt as follows:

while [[ \$response != q ]]; do read -n 1 -p [q]uit? response; echo; done

Hence, for your script, append this to the end of the bash -c command.

gnome-terminal --tab --title="tab 1" --command="bash -c 'python3 my_app.py; $SHELL'; 'while [[ \$response != q ]]; do read -n 1 -p [q]uit? response; echo; done'"

For the wrong python being used, you can either load ~/.bashrc by using bash -i, or you could explicitly specify the python version with /path/to/python3 instead of plain python3 in your command.

Hence, your final command is either

gnome-terminal --tab --title="tab 1" --command="bash -ci 'python3 my_app.py; $SHELL'; 'while [[ \$response != q ]]; do read -n 1 -p [q]uit? response; echo; done'"


gnome-terminal --tab --title="tab 1" --command="bash -c '/path/to/python3 my_app.py; $SHELL'; 'while [[ \$response != q ]]; do read -n 1 -p [q]uit? response; echo; done'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.