title: Assign a variable with 10 character long random string using /dev/random in bash?
body: <p>Trying to create a 10 character password and assign it to a variable and echo it back to the stdout.</p>
  
  <p>This is the script I've created so far, but it doesn't work. I know there are other ways to do this, but I've never been really good as using the <code>|</code> (pipe) to send information from 1 action to another when it involves more than 1 step.</p>
  
  <pre><code>#!/bin/bash
  tmp_pass=0
  if [ $tmp_pass=0 ]; then
          tmp_pass=`cat /dev/random`
          tmp_pass=$(head tmp_pass -c 10 | base64)
          echo $tmp_pass
  fi
  </code></pre>
  
  <p>Ideally, what I want is an example like this:</p>
  
  <ol>
  <li>Define the variable (eg - <code>tmp_pass</code>)</li>
  <li>Set variable to <code>0</code></li>
  <li>If variable <code>eq 0</code> then give it a new assignment</li>
  <li>Assign the variable the result of this:
  <ol>
  <li>Generate random string</li>
  <li>Grab the first 20 bytes of the random string</li>
  <li>Encode it as base64</li>
  <li>Cut it to the first 10 characters of the base64 </li>
  </ol></li>
  </ol>
  
  <hr>
  
  <p><strong>Note:</strong> This was not shown in my original script up above, but it did see it once using <code>echo filename(1:10)</code> or something like that to limit it to echo the first 10 characters of line 1.</p>
  
  <hr>
  
  <p>I understand this could be done on 1 single line, but am unsure of how to write it out, any examples would be most appreciated.</p>