title: Confused about bash behaviour - Bash / awk mystery
body: <p>Why I get this output while using the Bash shell? I don't understand because if I run the command directly I always get the same input (":0")</p>
  
  <pre><code>oneUser $ w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}'
  :0
  oneUser $ w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}'
  :0
  oneUser $ w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}'
  :0
  </code></pre>
  
  <p>But then:</p>
  
  <pre><code>oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  :0
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3}')
  oneUser $ echo $TEST
  :0
  </code></pre>
  
  <p>Edit 1: Output of "w -h oneUser"</p>
  
  <pre><code>oneUser  :0       :0               08:37   ?xdm?  20:23   0.17s /sbin/upstart --user
  oneUser  pts/5    :0               08:51    0.00s  1.73s  0.00s w -h oneUser
  </code></pre>
  
  <p>Edit 2: Printing $0 as well:</p>
  
  <pre><code>oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $0,$3}')
  oneUser $ echo $TEST
  
  oneUser $ TEST=$(w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $0,$3}')
  oneUser $ echo $TEST
  oneUser pts/5 :0 08:51 1.00s 1.82s 0.00s awk /w -h/ {if($3 ~ /^:/) print $0,$3} :0
  </code></pre>
  
  <p>Edit 3: I found that sometimes:</p>
  
  <pre><code>oneUser $ w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3,$0}'
  :0 oneUser  pts/5    :0               08:51    2.00s  1.97s  0.00s w -h oneUser
  oneUser $ w -h oneUser | awk '/w -h/ {if($3 ~ /^:/) print $3,$0}'
  :0 oneUser  pts/5    :0               08:51    3.00s  1.97s  0.00s awk /w -h/ {if($3 ~ /^:/) print $3,$0}
  </code></pre>