title: Bash and Awk Strange Behavior (DD-WRT)
body: <p>I am testing a small script in the DD-WRT Web interface that randomizes the router's MAC address. The script uses awk to do the randomization. The script works when awk is used <em>without</em> the shebang (#!/bin/bash), as well as vice versa (without awk but including the shebang). However, the script does not work when both the shebang <strong>and</strong> awk is used.</p>
  
  <p><strong>Works (uses awk, but no shebang):</strong></p>
  
  <pre><code>nvram set mac_clone_enable=1;
  nvram set def_hwaddr=$(awk 'function m(n){srand(systime()+n);return":"(10+int(rand()*99));}END{print "A4"m(1)m(2)m(3)m(4)m(5);}');
  nvram commit;
  rc restart;
  </code></pre>
  
  <p><strong>Also Works (has shebang, but no awk):</strong></p>
  
  <pre><code>#!/bin/bash
  
  nvram set mac_clone_enable=1;
  nvram set def_hwaddr="02:44:55:66:77:88";
  nvram commit;
  rc restart;
  </code></pre>
  
  <p><strong>Doesn't Work (shebang and awk):</strong></p>
  
  <pre><code>#!/bin/bash
  
  nvram set mac_clone_enable=1;
  nvram set def_hwaddr=$(awk 'function m(n){srand(systime()+n);return":"(10+int(rand()*99));}END{print "A4"m(1)m(2)m(3)m(4)m(5);}');
  nvram commit;
  rc restart;
  </code></pre>
  
  <p>I need the script to use awk and have the shebang, so it can be used in a cron job. What could be the problem?</p>