<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Don't get eval based macros in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32006#M6651</link>
    <description>&lt;P&gt;I just can't seem to understand how the eval based macros are supposed to work&lt;/P&gt;

&lt;P&gt;I wrote a very simple macro&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[TEST]
definition = "TEST"
iseval = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then a query to test the output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit | head 1 | eval test1=`TEST`  | eval test2=tostring(`TEST`) | table test*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output is one column 'test2' with a value of Null&lt;/P&gt;

&lt;P&gt;Why is that? Shouldn't the value be "TEST" for both columns? If not why not?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Dec 2011 00:59:39 GMT</pubDate>
    <dc:creator>andersmholmgren</dc:creator>
    <dc:date>2011-12-09T00:59:39Z</dc:date>
    <item>
      <title>Don't get eval based macros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32006#M6651</link>
      <description>&lt;P&gt;I just can't seem to understand how the eval based macros are supposed to work&lt;/P&gt;

&lt;P&gt;I wrote a very simple macro&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[TEST]
definition = "TEST"
iseval = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then a query to test the output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit | head 1 | eval test1=`TEST`  | eval test2=tostring(`TEST`) | table test*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output is one column 'test2' with a value of Null&lt;/P&gt;

&lt;P&gt;Why is that? Shouldn't the value be "TEST" for both columns? If not why not?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2011 00:59:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32006#M6651</guid>
      <dc:creator>andersmholmgren</dc:creator>
      <dc:date>2011-12-09T00:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Don't get eval based macros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32007#M6652</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;P&gt;[TEST]&lt;BR /&gt;
definition = "\"TEST\""&lt;BR /&gt;
iseval = 1&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2011 03:10:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32007#M6652</guid>
      <dc:creator>genthaler</dc:creator>
      <dc:date>2011-12-09T03:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Don't get eval based macros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32008#M6653</link>
      <description>&lt;P&gt;An eval-based macro returns a string, which is substituted into the query. Your macro returns the string &lt;CODE&gt;TEST&lt;/CODE&gt;, without quotes, so you are getting:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval test1=TEST  | eval test2=tostring(TEST) | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this case, &lt;CODE&gt;TEST&lt;/CODE&gt; is used as the name of a non-existent variable. You can get what you intended either with @genthaler's answer, or by putting the quotes in the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval test1="`TEST`"  | eval test2=tostring("`TEST`") | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2011 06:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32008#M6653</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2011-12-09T06:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Don't get eval based macros</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32009#M6654</link>
      <description>&lt;P&gt;Hi @gkanapathy,&lt;BR /&gt;
I just tried it, unfortunately quoted macro invocations don't get invoked. &lt;BR /&gt;
So instead of "TEST", you end up with the literal string "`TEST`".&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2011 13:37:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Don-t-get-eval-based-macros/m-p/32009#M6654</guid>
      <dc:creator>genthaler</dc:creator>
      <dc:date>2011-12-09T13:37:14Z</dc:date>
    </item>
  </channel>
</rss>

