title: sed result differs b/w command line & shell script
body: <p>The following <code>sed</code> command from commandline returns what I expect.</p>
  
  <pre><code>$ echo './Adobe ReaderScreenSnapz001.jpg' | sed -e 's/.*\./After-1\./' 
  After-1.jpg             &lt;--- result
  </code></pre>
  
  <p>Howerver, in the following bash script, <code>sed</code> seeems not to act as I expect.</p>
  
  <pre><code>#!/bin/bash
  beforeNamePrefix=$1
  i=1
  while IFS= read -r -u3 -d '' base_name; do
      echo $base_name
      rename=`(echo ${base_name} | sed -e s/.*\./After-$i./g)`
      echo 'Renamed to ' $rename
      i=$((i+1))
  done 3&lt; &lt;(find . -name "$beforeNamePrefix*" -print0)
  </code></pre>
  
  <p>Result (with several files with similar names in the same directory):</p>
  
  <pre><code>./Adobe ReaderScreenSnapz001.jpg
  Renamed to  After-1.         &lt;--- file extension is missing.
  ./Adobe ReaderScreenSnapz002.jpg
  Renamed to  After-2.
  ./Adobe ReaderScreenSnapz003.jpg
  Renamed to  After-3.
  ./Adobe ReaderScreenSnapz004.jpg
  Renamed to  After-4.
  </code></pre>
  
  <p>Where am I wrong? Thank you.</p>