Reputation: 264
I was working on a Django project and each time I open the project, I have to run these three commands one by one.
source virtualenv/bin/activate
(to activate virtual environment)
cd myproject
(to enter project folder)
python3 manage.py runserver
(to run the server)
Is there a way I can write these three commands in a text file (or some other file) so that a single command will run these three commands one by one?
Before running those three commands, terminal looks like this:
After running those three commands, the terminal should look like this:
Upvotes: 0
Views: 1429
Reputation: 1043
Try this:
In file runscript.sh
,
#!/bin/bash
source virtualenv/bin/activate
cd myproject
python3 manage.py runserver
Then run command: . runscript.sh
instead of ./runscript.sh
Upvotes: 1
Reputation: 364
Save following content to a file runserver.sh
#!/bin/bash
source virtualenv/bin/activate && cd myproject && python3 manage.py runserver
and
chmod 744 runserver.sh
And you can just run ./runserver.sh
&&
will ensure previous command was successful before running next command. If any command fails to run, it will abort rest.
Upvotes: 0