Score:3

Bash script - new Konsole closing

cf flag

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 .

Raffa avatar
jp flag
That's what [`--hold`](https://docs.kde.org/trunk5/en/konsole/konsole/command-line-options.html) apparently does.
terdon avatar
cn flag
Why do you need to open a new terminal? Do you want to launch the script from the GUI, but double clicking it? Can't you just launch it from a terminal? Also, why are you [sourcing the script instead of executing it](https://unix.stackexchange.com/q/43882/22222)? Is that needed? Does it work as expected if you remove `--hold` and then either remove `-e` or use `-e bash`?
Score:2
jp flag

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?

terdon avatar
cn flag
Why `--rcfile` instead of just running the script?
Raffa avatar
jp flag
@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.
terdon avatar
cn flag
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.
Raffa avatar
jp flag
@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 :-)
Matiata avatar
cf flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.