title: Casting a string to not allow for interpolation within a function in shell script
body: <p>I'm looking for some way to print an asterisk in a string passed to a program in shell. These problems are similar but I haven't been able to make any of the solutions work in my case: <a href="https://stackoverflow.com/questions/26833786/how-do-i-echo-an-asterisks-to-an-output">how do I echo an asterisks to an output</a>, <a href="https://stackoverflow.com/questions/25277037/printing-asterisk-in-bash-shell">Printing asterisk (*) in bash shell</a>, <a href="https://stackoverflow.com/questions/102049/how-do-i-escape-the-wildcard-asterisk-character-in-bash">How do I escape the wildcard/asterisk character in bash?</a>.</p>
  
  <p>I have the following script: </p>
  
  <pre><code>#!/bin/bash
  
  # First function
  function()
  {
  typeset -r str=$1
  typeset -i N=$2
  typeset -i i=0
  while [[ $i -lt $N ]];
  do
      echo $str| sed "s/&lt;token&gt;/$i/g"
      (( i+=1 ))
  done
  }
  
  # 'main' function
  doStuff()
  {
  foo.pl &lt;&lt; EOF
  
  some words $(function "input string with asterisk * and some &lt;token&gt; after it" 123)
  some more words
  
  EOF
      [ $? -eq 0 ] || logerror "Function 'doStuff' failed."
  }
  
  doStuff
  
  exit 0
  </code></pre>
  
  <p>When running the skript, the asterisk is substituted with the results of <code>echo *</code>.
  To fix this I have tried declaring <code>ASTERISK='*'</code> and substituting it in, as well as simply altering the function call to <code>$(function "input string with asterisk "'*'" and some &lt;token&gt; after it" 123)</code>, but neither did the trick.</p>
  
  <p>I suspect the problem is the <code>echo</code> statement inside <code>function</code>, but am not quite sure how to solve it, so my question would be if there is any way to cast <code>str</code> in <code>function</code> to not allow for interpolation once it is within <code>function</code>?</p>