title: How to define a shell script with variable number of arguments?
body: <p>I would like to define a simple abbreviation of a call to <code>gs</code> (ghostscript) via a shell script. The first argument(s) give all the files that should be merged, the last one gives the name of the output file. Obviously, the following does not work (it's just for showing the goal):</p>
  
  <pre><code>#!/bin/sh
  gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOUTPUTFILE=$last $1 $2 ...
  </code></pre>
  
  <p>How can this be done? </p>
  
  <p>One would typically call this script via <code>myscript infile1.pdf infile2.pdf ... outfile.pdf</code> or <code>myscript *.pdf outfile.pdf</code>.</p>