Ubuntu – Why doesn’t this bash script run as “sh runserver” recognize the “source” command

bashcommand linesource

I want to make a file which will run 2 command.

One will activate a virtual enviroment and after that, second command will run a server.

My file is called "runserver" and it looks like these:

#!/bin/bash
echo "Activating virtual enviroment"
source odoo-venv/bin/activate
echo "Running Odoo server"
./odoo12/odoo-bin --config=/etc/odoo12.conf

When I run this file with

sh runserver

It show the following error:

Activating virtual enviroment...
runserver: 3: source: not found
Running Odoo server...
...

It seems that my bash file is not recognizing the source command, how can I fix this?

Best Answer

sh doesn't run your script in bash but in dash which doesn't support source. Use . instead:

. odoo-venv/bin/activate

or run the script with bash:

/bin/bash runserver

See also a similar question on StackOverflow.