title: how do i verify presence of special characters in a bash password generator
body: <p>Supposed to be a simple bash script, but turned into a monster.  This is the 5th try.  You don't even want to see the 30 line monstrosity that was attempt #4..  :)</p>
  
  <p>Here's what I want to do:  Script generates a random password, with $1=password length, and $2=amount of special characters present in the output.</p>
  
  <p>Or at least, verify before sending to standard out, that at least 1 special character exists.  I would prefer the former, but settle for the latter.</p>
  
  <p>Here's my very simple 5th version of this script.  It has no verification, or $2:</p>
  
  <pre><code>#!/bin/bash
  cat /dev/urandom | tr -dc [=!=][=@=][=#=][=$=][=%=][=^=][:alnum:] | head -c $1
  </code></pre>
  
  <p>This works just fine, and it's a sufficiently secure password with Usage:</p>
  
  <pre><code>$ passgen 12
  2ZuQacN9M@6!
  </code></pre>
  
  <p>But it, of course, doesn't always print special characters, and it's become an obsession for me now to be able to allow selection of how many special characters are present in the output.  It's not as easy as I thought.</p>
  
  <p>Make sense?  </p>
  
  <p>By the way, I don't mind a complete rework of the code, I'd be very interested to see some creative solutions!</p>
  
  <p>(By the way:  I've tried to pipe it into egrep/grep in various ways, to no avail, but I have a feeling that is a possible solution...)</p>
  
  <p>Thanks
  Kevin</p>