title: Setting environment variables in shell script OS X
body: <p>I'm trying to create a Shell Script to automate my local dev environment. I need it start some processes (Redis, MongoDB, etc.), set the environment variables then start the local web server. I'm working on OS X El Capitan.</p>
  
  <p>Everything is working so far, except the environment variables. Here is the script:</p>
  
  <pre><code>#!/bin/bash
  
  # Starting the Redis Server
  if pgrep "redis-server" &gt; /dev/null
  then
      printf "Redis is already running.\n"
  else
      brew services start redis
  fi
  
  # Starting the Mongo Service
  if pgrep "mongod" &gt; /dev/null
  then
      printf "MongoDB is already running.\n"
  else
      brew services start mongodb
  fi
  
  # Starting the API Server
  printf "\nStarting API Server...\n"
  source path-to-file.env
  pm2 start path-to-server.js --name="api" --watch --silent
  
  # Starting the Auth Server
  printf "\nStarting Auth Server...\n"
  source path-to-file.env
  pm2 start path-to-server.js --name="auth" --watch --silent
  
  # Starting the Client Server
  printf "\nStarting Local Client...\n"
  source path-to-file.env
  pm2 start path-to-server.js --name="client" --watch --silent
  </code></pre>
  
  <p>The <code>.env</code> file is using the format <code>export VARIABLE="value"</code></p>
  
  <p>The environment variables are just not being set at all. But, if I run the exact command <code>source path-to-file.env</code> before running the script then it works. I'm wondering why the command would work independently but not inside the shell script.</p>
  
  <p>Any help would be appreciated.</p>