title: Cron job does NOT get the environment variables set in .bashrc
body: <p>Here is my cron job:</p>
  
  <pre><code>plee@dragon:~$ crontab -l
  * * * * * /bin/bash -l -c 'source ~/.bashrc; echo $EDITOR &gt; /tmp/cronjob.test'
  </code></pre>
  
  <p>and inside <code>~/.bashrc</code> file, I have <code>export EDITOR=vim</code>, but in the final <code>/tmp/cronjob.test</code> file, it's still empty?</p>
  
  <p>So how can I get the environment variables (set in <code>.bashrc</code> file) and use it in my cron job?</p>
  
  <pre><code>plee@dragon:~$ lsb_release -a
  No LSB modules are available.
  Distributor ID: Ubuntu
  Description:    Ubuntu 12.04 LTS
  Release:        12.04
  Codename:       precise
  plee@dragon:~$ uname -a
  Linux dragon 3.2.0-26-generic-pae #41-Ubuntu SMP Thu Jun 14 16:45:14 UTC 2012 i686 i686 i386 GNU/Linux
  </code></pre>
  
  <p>If use this:</p>
  
  <pre><code>* * * * * /bin/bash -l -c -x 'source ~/.bashrc; echo $EDITOR &gt; /tmp/cronjob.test' 2&gt; /tmp/cron.debug.res
  </code></pre>
  
  <p>In <code>/tmp/cron.debug.res</code>:</p>
  
  <pre><code>...
  ++ return 0
  + source /home/plee/.bashrc
  ++ '[' -z '' ']'
  ++ return
  + echo
  </code></pre>
  
  <p>BTW, the <code>.bashrc</code> file is the default one came with Ubuntu 12.04, with the exception that I added one line <code>export EDITOR=vim</code>.</p>
  
  <p>If I don't use the cron job, instead, just directly do this on the command line:</p>
  
  <pre><code>source .bashrc; echo $EDITOR # Output: vim
  </code></pre>