E.Praneeth
E.Praneeth

Reputation: 264

How to run set of terminal commands in a file one by one?

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:Image-1

After running those three commands, the terminal should look like this: Image-2

Upvotes: 0

Views: 1429

Answers (2)

Light Yagami
Light Yagami

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

Calvin Kim
Calvin Kim

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

Related Questions