title: Setting an environment variable before a command in Bash is not working for the second command in a pipe
body: <p>In a given shell, normally I'd set a variable or variables and then run a command. Recently I learned about the concept of prepending a variable definition to a command:</p>
  <pre><code>FOO=bar somecommand someargs
  </code></pre>
  <p>This works... kind of. It doesn't work when you're changing a <code>LC_*</code> variable (which seems to affect the command, but <strong>not</strong> its arguments, for example, <code>[a-z]</code> char ranges) or when piping output to another command thusly:</p>
  <pre><code>FOO=bar somecommand someargs | somecommand2  # somecommand2 is unaware of FOO
  </code></pre>
  <p>I can prepend somecommand2 with <code>FOO=bar</code> as well, which works, but which adds unwanted duplication, and it doesn't help with arguments that are interpreted depending on the variable (for example, <code>[a-z]</code>).</p>
  <p>So, what's a good way to do this on a single line?</p>
  <p>I'm thinking something on the order of:</p>
  <pre><code>FOO=bar (somecommand someargs | somecommand2)  # Doesn't actually work
  </code></pre>
  <hr/>
  <p>I got lots of good answers! The goal is to keep this a one-liner, preferably without using <code>export</code>. The method using a call to Bash was best overall, though the parenthetical version with <code>export</code> in it was a little more compact. The method of using redirection rather than a pipe is interesting as well.</p>