0

I have a shell script file ./bin/postactivate with following content:

#!/bin/sh

export STATIC_ROOT="/webapps/tsango/static/"
export MEDIA_ROOT="/webapps/tsango/media/"
export DATABASE_NAME="tsango"
export DJANGO_SETTINGS_MODULE="tsango.settings.vagrant"
export DATABASE_PASSWORD="password"
export BROKER_URL="amqp://tsango:password@localhost/tsango"
export DATABASE_USER="tsango"

I execute it with sudo sh ./bin/postactivate command. The command seems to run properly, i.e. no output from the command line.

However, when I use printenv to see the list of environment variables, none of the variables of the script is set.

I'm probably missing something... Can you tell me what?

1 Answers1

0

You should invoke the script as

source bin/postactivate

A process has environment variables. Let us assume your shell has a process id of 1003. You invoke sudo sh ./bin/postactivate. PID 1003 forks to create a new process, say 1108. process 1108 calls exec to change itself into sudo. sudo then changes itself into sh to process your script. So PID 1108 sets the environment variables for itself such as STATIC_ROOT. It then exits. Your shell (PID 1003) which was waiting for 1108 prints a new prompt, but nothing has changed in the environment for PID 1003.

icarus
  • 17,920