<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Shell variable assigment &#8211; a stupid bug</title>
	<atom:link href="http://tadek.pietraszek.org/blog/2007/01/19/shell-variable-assigment-a-stupid-bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadek.pietraszek.org/blog/2007/01/19/shell-variable-assigment-a-stupid-bug/</link>
	<description>Some random notes about computers, security, cool links and others.</description>
	<lastBuildDate>Thu, 15 Jul 2010 15:44:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Pascal Bauermeister</title>
		<link>http://tadek.pietraszek.org/blog/2007/01/19/shell-variable-assigment-a-stupid-bug/comment-page-1/#comment-26077</link>
		<dc:creator>Pascal Bauermeister</dc:creator>
		<pubDate>Fri, 12 Oct 2007 19:11:52 +0000</pubDate>
		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2007/01/19/shell-variable-assigment-a-stupid-bug/#comment-26077</guid>
		<description>&lt;p&gt;The two forms are both valid and have really different meanings !&lt;/p&gt;

&lt;p&gt;This one:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;VAR=value command
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;will define VAR for the scope of &#039;command&#039; only (and will make VAR known to &#039;command&#039;). But, as you noticed, the shell does variables expansion before the assignment. For instance, doing &lt;code&gt;EDITOR=emacs less file.txt&lt;/code&gt; will tell &#039;less&#039; to launch emacs upon pressing &#039;v&#039;.&lt;/p&gt;

&lt;p&gt;On the other hand, the second form&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;VAR=value; command&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;defines VAR for the remaining instance of the shell, but the shell will NOT pass it to subprocesses, so &lt;code&gt;Z=hello; env&lt;/code&gt; will NOT display any Z variable, whereas &lt;code&gt;Z=hello; echo $Z&lt;/code&gt; will display &#039;hello&#039; (because of shell variable expansion).&lt;/p&gt;

&lt;p&gt;A third form is using &#039;export&#039;:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;export VAR=value; command&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;. It is like the first form, but VAR will be passed to all subsequent commands.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;/p&gt;

&lt;p&gt;Pascal&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The two forms are both valid and have really different meanings !</p>

<p>This one:</p>

<p><pre><code>VAR=value command
</code></pre></p>

<p>will define VAR for the scope of &#8216;command&#8217; only (and will make VAR known to &#8216;command&#8217;). But, as you noticed, the shell does variables expansion before the assignment. For instance, doing <code>EDITOR=emacs less file.txt</code> will tell &#8216;less&#8217; to launch emacs upon pressing &#8216;v&#8217;.</p>

<p>On the other hand, the second form</p>

<p><pre><code>VAR=value; command</code></pre></p>

<p>defines VAR for the remaining instance of the shell, but the shell will NOT pass it to subprocesses, so <code>Z=hello; env</code> will NOT display any Z variable, whereas <code>Z=hello; echo $Z</code> will display &#8216;hello&#8217; (because of shell variable expansion).</p>

<p>A third form is using &#8216;export&#8217;:</p>

<p><pre><code>export VAR=value; command</code></pre></p>

<p>. It is like the first form, but VAR will be passed to all subsequent commands.</p>

<p>Cheers,</p>

<p>Pascal</p>]]></content:encoded>
	</item>
</channel>
</rss>
