title: (standard_in) 1: illegal character: ^M - dos2Unix not working?
body: <p>My Script is :</p>
  <pre><code>#!/bin/bash
  LGREEN='\033[1;32m'
  LBLUE='\033[1;36m'
  NC='\033[0m'
  
  function convertToTime {
      min=$(echo &quot;$min+$sec/60&quot; | bc)
      sec=$(echo &quot;$sec%60&quot; | bc)
      hrs=$(echo &quot;$hrs+$min/60&quot; | bc)
      min=$(echo &quot;$min%60&quot; | bc)
  }
  
  function convertToTimeTotal {
      totalMin=$(echo &quot;$totalMin+$totalSec/60&quot; | bc)
      totalSec=$(echo &quot;$totalSec%60&quot; | bc)
      totalHrs=$(echo &quot;$totalHrs+$totalMin/60&quot; | bc)
      totalMin=$(echo &quot;$totalMin%60&quot; | bc)
  }
  
  totalSec=0
  totalMin=0
  totalHrs=0
  
  function recursiveDirFinder {
      presentDir=$1
      cd &quot;$presentDir&quot;
      ls &gt;filelist.tmp
      sec=0
      min=0
      hrs=0
      while
          read fileName  
          do
          if 
              test -d &quot;$fileName&quot;
              then
              presentDir+=&quot;/$fileName&quot;
              recursiveDirFinder &quot;$presentDir&quot;
              presentDir=$1
          else
              if [[ $fileName == *.mp4 ]]; then
                  s=`ffprobe -v quiet -of csv=p=0 -show_entries format=duration &quot;$fileName&quot;`
                  sec=$(echo &quot;$sec+$s&quot; | bc)
              fi
          fi
      done &lt;filelist.tmp
      convertToTime
      echo -e &quot;Video Duration in $1 is ${LBLUE}$hrs:$min:$sec${NC}&quot;
      totalSec=$(echo &quot;$totalSec+$sec&quot; | bc)
      rm filelist.tmp
      cd ..
  }
  
  recursiveDirFinder &quot;E:/RBR Lectures&quot;
  convertToTimeTotal
  echo -e &quot;Total Duration is ${LGREEN}$totalHrs:$totalMin:$totalSec${NC}&quot;
  </code></pre>
  <p>I originally wrote this on Ubuntu 16.04.1 LTS x64. I then installed cygwin on Win8 x64 and tried to run the script. I get the errors :</p>
  <blockquote>
  <p>(standard_in) 1: illegal character: ^M</p>
  <p>(standard_in) 1: syntax error</p>
  </blockquote>
  <p>I searched a little, and found that it's primarily caused by unix characters in DOS and vice versa. I ran <code>dos2unix</code> on the file <code>durationAdder.sh</code> (my script) and the output suggested successful conversion. But I still keep getting the error. Why is this, and how do I fix it?</p>