title: How to use functions in bash?
body: <p>I have a file which has hashes of the files against their filename.
  For example,</p>
  
  <pre><code>fb7e0a4408e46fd5573ffb9e73aec021a9dcf426235c0ccfc37d2f5e09a68a23 /path/to/some/file
  237e0a4408e46fe3573f239e73aec021a9dcf426235c023fc37d2f5e09a68a12 /path/to/another/file
  ... and so on...
  </code></pre>
  
  <p>I need the hash converted to <code>base64</code> encoded format.</p>
  
  <p>So I used combination of a bash function and <code>awk</code>.</p>
  
  <p>Here is what I wrote,</p>
  
  <pre><code>#!/bin/sh
  base64Encode() {
       $1 | openssl base64 -A
  }
  awk ' { t = base64Encode $1; print t } ' file.txt
  </code></pre>
  
  <p>But it does not seem to work. I'm using <code>hashdeep</code> to generate the hash-list file and <code>hashdeep</code> does not support <code>base64</code> encoded output. That is why I'm using <code>openssl</code>.</p>
  
  <p>Any help or tips regarding this would be great!</p>
  
  <p>Edit: </p>
  
  <p>The given answers work but I'm having some other issue it seems.</p>
  
  <p>Usually <code>cat filename | openssl dgst -sha256 | openssl base64 -A</code> gives a <code>base64</code> encoded output for <code>filename</code> file which is absoutely correct,
  and output from <code>hashdeep</code> matched output from <code>cat filename | openssl dgst -sha256</code>.
  So, I thought of piping the output obtained from above step to <code>openssl base64 -A</code> for <code>base64</code> output. But, still I get different values from actual result.</p>
  
  <p>Although this might be suited for a separate question perhaps, but still I would appreciate any support on this.</p>