title: Shell Script with sqlplus and special characters on password
body: <p>I have a question that mix Linux / Unix shell-scripting and sqlplus (Oracle) that is driving me crazy. :-)</p>
  
  <p>sqlplus utilize a syntax like this:</p>
  
  <pre><code>./sqlplus johnF/mypassword@127.0.0.1:1521/SID
  </code></pre>
  
  <p>And it works fine. However my password is not simple as "mypassword", it utilize "!" and "@" and sometimes even "\". For this example, let's suppose that my password is !p@ssword</p>
  
  <p>If I use the following syntax in sqlplus it works:</p>
  
  <pre><code>./sqlplus johnF/'"!p@ssword"'@127.0.0.1:1521/SID
  </code></pre>
  
  <p>That's great. However I wanted to use it in a shell script that get call sqlplus and get many parameters from files (username, password, SID and SQL QUERY), just for example let me use a reduced code.</p>
  
  <pre><code>#!/bin/bash
  
  while IFS=: read -r line
  do
  
          echo "./sqlplus johnF/$line@127.0.0.1:1521/SID" 
          echo -e 'select 1 from dual;\nexit;' |  ./sqlplus johnF/$line@127.0.0.1:1521/SID
  
  done &lt; $1
  </code></pre>
  
  <p>I have attempted to fix it in many ways, including:</p>
  
  <pre><code>echo -e 'select 1 from dual;\nexit;' |  ./sqlplus johnF/'"$line"'@127.0.0.1:1521/SID
  echo -e 'select 1 from dual;\nexit;' |  ./sqlplus johnF/'\"$line\"'@127.0.0.1:1521/SID
  echo -e 'select 1 from dual;\nexit;' |  ./sqlplus johnF/\'\"$line\"\'@127.0.0.1:1521/SID
  </code></pre>
  
  <p>And many others and all fails, in a few cases the first echo print the output exactly as it should be passed to sqlplus, but it never works, returns login denied (wrong password) or connection issues (maybe the @ being intercepted as wrong target).</p>
  
  <p>How to solve this puzzle?</p>
  
  <p>Thanks.</p>