I need a bash script that does the following:
- open a new terminal
- change to a specific directory
- run a command in that directory
- keep the terminal open for further use
Specifically I want to:
- open the konsole terminal
- change to
/my/work/dir/
- inside
/my/work/dir/
, runsource bin/activate
- after that I need to run further commands inside
/my/work/dir/
, e.g.ls
A very similar question was given the following answer for the script (adapted to my requirements):
#!/usr/bin/env bash
konsole --noclose --workdir /my/work/dir/ -e 'bash -c 'source bin/activate''
This does open a new terminal inside /my/work/dir/
, but the terminal is not interactive. The
user@userMachine: /my/work/dir$
is missing that allows me to run further commands and anything I type (e.g. pwd
) returns nothing, just new lines.
You need to specify what the terminal to do after executing the command
source bin/activate
. You want an active bash session so you need to runbash
. In addition there is a mes with the quotes. So the script could be:&
at the end is added in order to keep the main terminal usable, in case you are executing that script from other terminal window.the
exec
command could be omitted, and you can use onlybash
.Here are few answers of similar questions, dedicated to
gnome-terminal
:how can I open a extra console and run a program in it with one command?
Open a new terminal and source scripts
How to open one (or more) gnome-terminal window with few tabs, each with different profile, when start/reboot the computer?
I am not able to comment, but from what I understand I may suggest