title: Search and Replace in a variable string with Shell scripts
body: <p>I am in dilemma about how could I search and replace a particular character in a variable of a shell script. </p>
  
  <p>e.g. I have a condition where I need to pass <code>'~'</code> to the java program but I should pass it as <code>'/~'</code> to avoid it being intercepted as $HOME. I have a shell variable e.g. <code>$1 = '.-~'</code>  and I am passing it directly to the Java program as an argument. So how could I modify this variable in such a way that it searches for <code>'~'</code> and if it finds then changes <code>$1 = '.-/~'</code> so as to avoid the error in Java program.</p>
  
  <p>I tried <code>$(1//~//~)</code> but it gives me an error.</p>
  
  <p>Also this gave me an error.</p>
  
  <pre><code>sed 's#~#/#g' &lt;&lt;&lt; $x;
  </code></pre>