undefined variables

In 3.0rc2 how can I determine if a global variable exists or not:

[x@x] > :put [:typeof $anything]
syntax error (line 1 column 16)

In 2.9.x it would return ‘nil’… How can I determine if a variable exists or not? I believe this is happening because 3.0 is parsing the variable name for screen validation.

:if ([ :typeof $anything ] = nil ) do={ :global anything 0.0.0.0/0 }

Thx,
Sam

Variable will exist anyway, because in 3.0 all variables must be defined before used in script.

i know that i can define it, however i wish to check if it’s already been initialized. I don’t want to overwrite the value if it’s already there.

if you have defined variable like this:
:global strVar “my string”;

next time you do:
:global strVar;
it’s value will remain previous, in this case “my tring”.

I hope you understand what i mean.

You can check only if variable has no value:

:if ( $strVar = “” ) do= { … }

ah, i will try that. if i can declare the variable with nothing and have it stay the same that will work. Thank you.

I have same question
because
when the router shut down global variables will be clear
so i want to check “does global variables is exist?”

Its already posted above on how to test for a variable.

:if ( $strVar = "" ) do= { .... }