title: Nested scripts inside while read file
body: <p>I have 3 scripts:</p>
  
  <p>foo1.sh - while reading each line of a file calls the script foo2.sh</p>
  
  <pre><code>#!/bin/bash
  
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &amp;&amp; pwd)"
  I=1
  
  while read LINE  || [ -n "$LINE" ]; do
      ID=$(printf "%05d\n" $I)
      ((I++))
      IDS=($(awk -F "," '{print $1; print $2}' &lt;&lt;&lt; $LINE))
  
      $SCRIPT_DIR/foo2.sh $ID ${IDS[0]} ${IDS[1]} '-hello'
  done &lt; $SCRIPT_DIR/a.txt
  </code></pre>
  
  <p>foo2.sh - calls the script foo3.sh</p>
  
  <pre><code>#!/bin/bash
  
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &amp;&amp; pwd)"
  
  $SCRIPT_DIR/foo3.sh $1 $2 $3 $4
  </code></pre>
  
  <p>foo3.sh - calls a function that logs stuff</p>
  
  <pre><code>#!/bin/bash
  
  info(){
      echo "[INFO][${ARG1}|${ARG2}|${ARG3}] - $1"
  }
  
  ARG1=$1
  ARG2=$2
  ARG3=$3
  ARG4=$4
  
  info "START"
  info "END"
  </code></pre>
  
  <p>And I have the file a.txt with the following data:</p>
  
  <pre><code>foo11,foo12
  foo21,foo22
  </code></pre>
  
  <p>When I run ./foo1.sh, the following occurs:</p>
  
  <pre><code>] - START001|foo11|foo12
  ] - END00001|foo11|foo12
  [INFO][00002|foo21|foo22] - START
  [INFO][00002|foo21|foo22] - END
  </code></pre>
  
  <p>I don't understand why. If I echo every ARG of foo3, they are correct.
  If I create the same function in foo2, the output is correct.</p>
  
  <p>Is it because of the \n in the 1st line in the a.txt?</p>