title: how to replace a variable in shell script string
body: <p>I'm having problems getting this to work...</p>
  
  <p>I have a variable that is holding a SQL to with a placeholder:</p>
  
  <pre><code>echo $SQL
  SELECT PX_PROMOTION_ID, PRIORITY, STATUS, EXCLSVE, TYPE, PERORDLMT, PERSHOPPERLMT, TOTALLMT, RSV_INT, PX_GROUP_ID, CAMPAIGN_ID, STOREENT_ID, VERSION, REVISION, EFFECTIVE, TRANSFER, CDREQUIRED, EXPIRE, LASTUPDATEBY, TO_CHAR(LASTUPDATE, 'YYYYMMDD HH24MMSS') AS LASTUPDATE, TO_CHAR(STARTDATE, 'YYYYMMDD HH24MMSS') AS STARTDATE, TO_CHAR(ENDDATE, 'YYYYMMDD HH24MMSS') AS ENDDATE, TO_CHAR(RSV_TIME, 'YYYYMMDD HH24MMSS') AS RSV_TIME, RSV_REAL, TGTSALES, NAME, CODE, RSV_VCH, OPTCOUNTER FROM PX_PROMOTION WHERE LASTUPDATE BETWEEN (SELECT MAX(BATCHSTART) FROM XRPTEBATCHCONTROL) AND TIMESTAMP('$BATCH_END')
  </code></pre>
  
  <p>I have another variable that holds the value:</p>
  
  <pre><code>echo $BATCH_END
  2012-11-14 17:06:13
  </code></pre>
  
  <p>I want to replace the placeholder with the value. I'm not particularly great at Unix scripting, but I've tried this:</p>
  
  <pre><code>echo $SQL | sed -e "s/'$BATCH_END/$BATCH_END/g"
  </code></pre>
  
  <p>but it still doesn't get replaced...</p>
  
  <p>Can anyone help? I want to replace the placeholder, and keep the final string assigned to $SQL</p>
  
  <p>I also need to know how to get the value of the output back into the variable, for example, I tried:</p>
  
  <pre><code> SQL=`echo "$SQL" | echo "${SQL//\$BATCH_END/$BATCH_END}"`
  </code></pre>