title: How to check the type of an awk variable?
body: <p>The Beta release of gawk 4.2.0, available in <a href="http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz" rel="nofollow noreferrer">http://www.skeeve.com/gawk/gawk-4.1.65.tar.gz</a> is <em>a major release, with many significant new features</em>.</p>
  <p>I previously asked about <a href="https://stackoverflow.com/q/46609071/1983854">What is the behaviour of FS = &quot; &quot; in GNU Awk 4.2?</a>, and now I noticed the brand new <code>typeof()</code> function to deprecate <a href="https://stackoverflow.com/a/34414365/1983854"><code>isarray()</code></a>:</p>
  <blockquote>
  <p>Changes from 4.1.4 to 4.2.0</p>
  <ol start="15">
  <li>The new <code>typeof()</code> function can be used to indicate if a variable or     array element is an array, regexp, string or number. The <code>isarray()</code> function is deprecated in favor of <code>typeof()</code>.</li>
  </ol>
  </blockquote>
  <p>I could cover four cases: string, number, array and unassigned:</p>
  <pre><code>$ awk 'BEGIN {print typeof(&quot;a&quot;)}'
  string
  $ awk 'BEGIN {print typeof(1)}'
  number
  $ awk 'BEGIN {print typeof(a[1])}'
  unassigned
  $ awk 'BEGIN {a[1]=1; print typeof(a)}'
  array
  </code></pre>
  <p>However, I struggle to get &quot;regexp&quot; since none of my attempts reach that and always yield &quot;number&quot;:</p>
  <pre><code>$ awk 'BEGIN {print typeof(/a/)}'
  number
  $ awk 'BEGIN {print typeof(/a*/)}'
  number
  $ awk 'BEGIN {print typeof(/a*d/)}'
  number
  $ awk 'BEGIN {print typeof(!/a*d/)}'
  number
  $ awk -v var=&quot;/a/&quot; 'BEGIN{print typeof(var)}'
  string
  $ awk -v var=/a/ 'BEGIN{print typeof(var)}'
  string
  </code></pre>
  <p>How can I get a variable to be defined as &quot;regexp&quot;?</p>
  <p>I noticed the previous bullet:</p>
  <blockquote>
  <ol start="14">
  <li>Gawk now supports strongly typed regexp constants. Such constants     look like @/.../.  You can assign them to variables, pass them to     functions, use them in ~, !~ and the case part of a switch statement.     More details are provided in the manual.</li>
  </ol>
  </blockquote>
  <p>And tried a bit, but with no luck:</p>
  <pre><code>$ awk -v pat=@/a/ '{print typeof(pat)}' &lt;&lt;&lt; &quot;bla ble&quot;
  string
  </code></pre>