title: How to handle "--" in the shell script arguments?
body: <p>This question has 3 parts, and each alone is easy, but combined together is not trivial (at least for me) :)</p>
  
  <p>Need write a script what should take as its arguments:</p>
  
  <ol>
  <li>one name of another command</li>
  <li>several arguments for the command</li>
  <li>list of files</li>
  </ol>
  
  <p>Examples:</p>
  
  <pre><code>./my_script head -100 a.txt b.txt ./xxx/*.txt
  ./my_script sed -n 's/xxx/aaa/' *.txt
  </code></pre>
  
  <p>and so on.</p>
  
  <p>Inside my script for some reason I need distinguish</p>
  
  <ul>
  <li>what is the command</li>
  <li>what are the arguments for the command</li>
  <li>what are the files</li>
  </ul>
  
  <p>so probably the most standard way write the above examples is:</p>
  
  <pre><code>./my_script head -100 -- a.txt b.txt ./xxx/*.txt
  ./my_script sed -n 's/xxx/aaa/' -- *.txt
  </code></pre>
  
  <p><strong>Question1:</strong> Is here any better solution?</p>
  
  <p>Processing in ./my_script (first attempt):</p>
  
  <pre><code>command="$1";shift
  args=`echo $* | sed 's/--.*//'`
  filenames=`echo $* | sed 's/.*--//'`
  
  #... some additional processing ...
  
  "$command" "$args" $filenames #execute the command with args and files
  </code></pre>
  
  <p>This solution will fail when the <code>filenames</code> will contain <code>spaces</code> and/or '--', e.g.<br>
  /some--path/to/more/idiotic file name.txt</p>
  
  <p><strong>Question2:</strong> How properly get <code>$command</code> its <code>$args</code> and <code>$filenames</code> for the later execution?</p>
  
  <p><strong>Question3:</strong> - how to achieve the following style of execution?</p>
  
  <pre><code>echo $filenames | $command $args #but want one filename = one line (like ls -1)
  </code></pre>
  
  <p>Is here nice shell solution, or need to use for example perl?</p>