title: How bash IFS is working in this example?
body: <p>I am reading about <a href="http://tldp.org/LDP/abs/html/internalvariables.html" rel="nofollow">bash internal variables</a> and came across this <code>IFS</code> example:</p>
  
  <pre><code>output_args_one_per_line()
  {
    for arg
    do
      echo "[$arg]"
    done #  ^    ^   Embed within brackets, for your viewing pleasure.
  }
  </code></pre>
  
  <p><strong>CASE1</strong></p>
  
  <pre><code>IFS=" "
  var=" a  b c   "
  
  output_args_one_per_line $var
  #OUTPUT
  # [a]
  # [b]
  # [c]
  </code></pre>
  
  <p><strong>CASE2</strong></p>
  
  <pre><code>IFS=:
  var=":a::b:c:::"               # Same pattern as above
  CASE2   
                          # but substituting ":" for " "  ...
  output_args_one_per_line $var
  # []
  # [a]
  # []
  # [b]
  # [c]
  # []
  # []
  </code></pre>
  
  <p>Now, according to my understanding if value of <code>IFS</code> is default <code>\t\n</code> than leading and trailing whitespaces are removed. So, for case1 bash sees <code>var</code> as <code>a b c</code> therefore the output.</p>
  
  <p>For case2 according to me bash sees <code>var</code> as <code>|a||b|c|||</code> treat <code>|</code> as <code>space</code> here. I checked it using </p>
  
  <pre><code>Noob@Noob:~/tmp$ IFS=$':' FOO=$":a::b:c:::"; echo $FOO $'x'
   a  b c   x
  </code></pre>
  
  <p>So, my expected output for case 2 is</p>
  
  <pre><code># []
  # [a]
  # []
  # []
  # [b]
  # [c]
  # []
  # []
  # []
  </code></pre>
  
  <p>So, can someone explain to me internally how bash is treating <code>var</code> in case 2 and where am I going wrong iin my understanding.</p>