title: Set environment variable in bash in Rmarkdown
body: <p>I would like to set an environment variable within an Rmarkdown bash chunk and access it in later R chunks. Essentially, I would like to do the opposite of this question, which has been answered many times: <a href="https://stackoverflow.com/questions/43516681/rmarkdown-accessing-parameter-from-bash-chunk">RMarkdown accessing parameter from bash chunk</a></p>
  
  <p>I can pass a parameter into the bash chunk using R:</p>
  
  <pre><code>Sys.setenv(MY_PARAM = 'param value')
  </code></pre>
  
  <p>And access it in bash:</p>
  
  <pre><code>echo $MY_PARAM
  </code></pre>
  
  <blockquote>
    <p>param value</p>
  </blockquote>
  
  <p>But when I try to store an environment variable in bash I am unable to access it in R later:</p>
  
  <p>Bash again:</p>
  
  <pre><code>export MY_PARAM2="param value"
  echo $MY_PARAM2
  </code></pre>
  
  <blockquote>
    <p>param value</p>
  </blockquote>
  
  <p>A later R chunk:</p>
  
  <pre><code>Sys.getenv('MY_PARAM2')
  </code></pre>
  
  <blockquote>
    <p>[1] " "</p>
  </blockquote>
  
  <p>I would be open to any other ideas on how to pass variables out of the bash code chunk for use in later chunks. Here's the whole thing for replication in Rmarkdown:</p>
  
  <pre><code>```{r}
  Sys.setenv(MY_PARAM = 'param value')
  ```
  
  ```{bash}
  echo $MY_PARAM
  ```
  
  ```{bash}
  export MY_OTHER_PARAM="param value"
  echo $MY_OTHER_PARAM
  ```
  
  ```{r}
  Sys.getenv('MY_OTHER_PARAM')
  ```
  </code></pre>