3

I'm working on a project that requires me to open some new bash windows to start the docker, server, etc. of the project. I'm trying to make a script so I can start things faster. So far I have this:

#!/bin/bash
cd dev/proj/prod/;
konsole --hold --new-tab -e echo "Hello World";

The problem is that a new window is open in Konsole with the text displayed, but the bash is stuck:

(bash image).

I'm running the script with . proj.sh .

terdon
  • 100,812
Matiata
  • 33

1 Answers1

2

I'm working on a project that requires me to open some new bash windows to start the docker, server, etc. of the project . . . I'm running the script with . proj.sh

The proper way to do that is to remove konsole --hold --new-tab -e ... from your proj.sh file (keeping other commands you want executed in the new Konsole's Bash shell e.g. cd, docker ... etc.) and then source that file in the new Bash shell that will be launched in a new konsole window like so:

konsole --hold --new-tab -e '/bin/bash --rcfile /path/to/proj.sh'

or to detach it from the original terminal's Bash shell:

konsole --hold --new-tab -e '/bin/bash --rcfile /path/to/proj.sh' & disown

For more explanation, please see this related post about gnome-terminal:

How to launch gnome-terminal and activate a python virtual environment?

Raffa
  • 32,237
  • Why --rcfile instead of just running the script? – terdon Sep 01 '23 at 12:46
  • @terdon User’s sometimes source a script in order to achieve something … e.g. a custom environment focused in one main purpose and want that to automatically happen in a new separate terminal window … I think the asker is trying to do that AFAIK … Please see the linked other post in my answer to get an idea of why might this situation be desired by some users. – Raffa Sep 01 '23 at 13:36
  • Oh, I know why it could be desired. However, based on the OP here, it doesn't look like it is desired. It's what the OP is doing, no argument there, but given the commands being run it doesn't make much sense. – terdon Sep 01 '23 at 13:37
  • @terdon The echo "Hello World" appears to be a test command not a production command … I still might be wrong though … But launching a new terminal is more indicative towards needing a work environment set vs. needing to run a script once … Still an assumption though :-) – Raffa Sep 01 '23 at 13:46
  • 1
    That's right, I need an interactive session in case I need to restart the server or run any other command. This answer is just what I needed. I created a new script file that starts the terminals and they --rcfile the scripts to start docker, server, etc. Thanks. – Matiata Sep 01 '23 at 14:54