title: How can I pass in arguments to a command line Java program and escape all special characters?
body: <p>I have a command line Java program, and I am passing in the arguments via a bash script. The line is located in my bash script file and is as follows:</p>
  
  <pre><code>java -cp "$PROJECT_LOC" Main.main "@$"
  </code></pre>
  
  <p>The bash script is in my path so I can call the program directly by typing in</p>
  
  <pre><code>&lt;projectName&gt; arg1 arg2 arg3
  </code></pre>
  
  <p>directly into my terminal (I am on OS X Yosemite).</p>
  
  <p>When an ampersand is passed in as an argument, it is not read as a plain ampersand character but as the special character ampersand which executes some process. 
  However, I would like to be able to simply pass in an ampersand as an argument but not have to make the user of the program manually escape the character.</p>
  
  <p>Is there a way to handle the passing in of an ampersand (or any other special characters) in my bash script such that any and all special characters in the input would be escaped, and then be passed in as the (now cleaned) args of the Java program?</p>
  
  <p>Edit: To be more clear, I want to be able to do the following in my terminal:</p>
  
  <pre><code>&lt;projectName&gt; arg1 arg&amp;2 arg3
  </code></pre>
  
  <p>I want this input to be equivalent to this:</p>
  
  <pre><code>&lt;projectName&gt; 'arg1' arg&amp;2' 'arg3'
  </code></pre>
  
  <p>But I am looking for a way to not to have to force the user to escape the special characters themselves (do everything behind the scenes).</p>