title: Exporting environment variables from script with whitespaces
body: <p>Big picture of the issue: I'm creating Golang script (<a href="http://github.com/Droplr/aws-env" rel="nofollow noreferrer">http://github.com/Droplr/aws-env</a>) that will be used to secure retrieve environment variables and export them to be used for another process.</p>
  
  <p>As we know, it's not easy doable as script can't export vars <em>outside</em> [1], [2].</p>
  
  <p>So the way we were trying to do it, is basically <a href="https://github.com/Droplr/aws-env/blob/master/aws-env.go#L60" rel="nofollow noreferrer">outputing export statements</a> and then using bash backticks to run that command.</p>
  
  <p>Final usage is like:</p>
  
  <pre><code>`aws-env` &amp;&amp; printenv
  </code></pre>
  
  <p>where printenv should show variables exported by evaluated aws-env output (which contains "export" statements).</p>
  
  <p>The problem arises with variables that contain spaces/new lines etc.</p>
  
  <p>Simplifying underline code, this one works:</p>
  
  <pre><code>$ export A=b\ b
  $ printenv | grep A=
  A=b b
  </code></pre>
  
  <p>And this - not:</p>
  
  <pre><code>$ `echo export A=b\ b`
  $ printenv | grep A=
  A=b
  </code></pre>
  
  <p>I've went over other Stackoverflow discussions ([3]) but couldn't find clear answer for that problem (mostly the answer is to not use backticks, but with our overall problem we try to solve it wont be so easy...)</p>
  
  <ul>
  <li>[1] <a href="https://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell">Can a shell script set environment variables of the calling shell?</a></li>
  <li>[2] <a href="https://unix.stackexchange.com/questions/79064/how-to-export-variables-from-a-file">https://unix.stackexchange.com/questions/79064/how-to-export-variables-from-a-file</a></li>
  <li>[3] <a href="https://stackoverflow.com/questions/3479133/bash-escape-characters-in-backticks">Bash: escape characters in backticks</a></li>
  </ul>