title: bash: how to delete elements from an array based on a pattern
body: <p>Say I have a bash array (e.g. the array of all parameters) and want to delete all parameters matching a certain pattern or alternatively copy all remaining elements to a new array. Alternatively, the other way round, keep elements matching a pattern.</p>
  
  <p>An example for illustration:</p>
  
  <pre><code>x=(preffoo bar foo prefbaz baz prefbar)
  </code></pre>
  
  <p>and I want to delete everything starting with <code>pref</code> in order to get</p>
  
  <pre><code>y=(bar foo baz)
  </code></pre>
  
  <p>(the order is not relevant)</p>
  
  <p>What if I want the same thing for a list of words separated by whitespace?</p>
  
  <pre><code>x="preffoo bar foo prefbaz baz prefbar"
  </code></pre>
  
  <p>and again delete everything starting with <code>pref</code> in order to get</p>
  
  <pre><code>y="bar foo baz"
  </code></pre>