title: Running perl command form shell script
body: <p>I have a list of points coordinates in 2 column format first column x-axis, second column y-axis, and I'd like to make a script to rescale the axis.</p>
  <blockquote>
  <p><strong>input file example</strong><br />
  4 3<br />
  3 6</p>
  <p><strong>output file example (rescale to 10 10)</strong><br />
  10 5<br />
  7.5 10</p>
  </blockquote>
  <p>To do that, I first get the biggest coordinate on both column (using <code>sort</code>, <code>head</code> and <code>cut</code>), and then I interpolate all lines using a perl substitute regexp.</p>
  <p>So I scripted that :</p>
  <pre><code>#!/bin/sh
  # run:  $ ./normalize x y input_file output_file
  X=$1
  Y=$2
  INPUT=$3
  OUTPUT=$4
  
  BIGGEST_FIRST_COLUMN=$(sort -nrk1 $INPUT | head -n1 | cut -d ' ' -f 1)
  BIGGEST_SECOND_COLUMN=$(sort -nrk2 $INPUT | head -n1 | cut -d ' ' -f 2)
  
  PERL_CMD=&quot;'s!([\d.]+)\s([\d.]+)!(\$1/$BIGGEST_FIRST_COLUMN*$X).\&quot; \&quot;.(\$2/$BIGGEST_SECOND_COLUMN*$Y)!e'&quot;
  
  CMD=&quot;perl -pe $PERL_CMD $INPUT &gt; $OUTPUT&quot;
  echo &quot;Run the following cmd : &quot;
  echo $CMD
  
  $CMD
  </code></pre>
  <p>This code output the perl onliner I want to run and then try to run it.
  At this point, the perl oneliner is working : I can copy-paste it and running it by hand and it gives the correct output. Nevertheless, I got a bug when the script run it automatically :</p>
  <pre><code>Can't find string terminator &quot;'&quot; anywhere before EOF at -e line 1.
  </code></pre>
  <p>I suppose this is due to some problem in my comprehension of <code>&quot;</code> and <code>'</code> in shell, but at this point, I have no idea... So if you have any tips, welcome</p>