title: SED bad substitution error
body: <p>Here's my problem, I have written the following line of code to format properly a list of files found recursively in a directory. </p>
  
  <pre><code>find * | sed -e '/\(.*\..*\)/ !d' | sed -e "s/^.*/\${File} \${INST\_FILES} &amp;/" | sed -e "s/\( \)\([a-zA-Z0-9]*\/\)/\/\2/" | sed -e "s/\(\/\)\([a-zA-Z0-9\_\-\(\)\{\}\$]*\.[a-zA-Z0-9]*\)/ \2/"
  </code></pre>
  
  <p>The second step is to write the output of this command in a script. While the code above has the expected behavior, the problem occurs when I try to store its output to a variable, I get a bad substitution error from the first sed command in the line.</p>
  
  <pre><code>#!/bin/bash
  nsisscript=myscript.sh
  FILES=*
  for f in $(find $FILES); do 
  v=`echo $f | sed -e '/\(.*\..*\)/ !d' | sed -e "s/^.*/\${File} \${INST\_FILES} &amp;/" | sed -e "s/\( \)\([a-zA-Z0-9]*\/\)/\/\2/" | sed -e "s/\(\/\)\([a-zA-Z0-9\_\-\(\)\{\}\$]*\.[a-zA-Z0-9]*\)/ \2/"`
  sed -i.backup -e "s/\;Insert files here/$v\\n&amp;/" $nsisscript 
  done 
  </code></pre>
  
  <p>Could you please help me understand what the difference is between the two cases and why I get this error ?</p>
  
  <p>Thanks in advance!</p>