Skip to main content
1-Visitor
September 26, 2011
Question

ACL test for environment variable

  • September 26, 2011
  • 12 replies
  • 2298 views
Hi,

In my instance.acl script, I'm trying to test for the existence of an external variable and source the appropriate file depending on whether or not it's defined. This is how I'm trying to do it, but it doesn't seem to be working:

if ($main::ENV["XPS3_HOME"] != ") {
source $XPS3_HOME\XPSDocs\entities\commonStartup.acl
} else {
source $XPS_HOME\XPSDocs\entities\commonStartup.acl
};

That is, when "XPS3_HOME" is not defined, I'm getting an error during startup indicating that at line 2 it's trying to use an undefined variable. Anyone know the correct way of doing this test?

Thanks
Dave
Siemens

    12 replies

    18-Opal
    September 27, 2011
    Hi Yves--

    Very interesting. I tested it out and you are absolutely right. I stand corrected, and I apologize for leading Dave astray on that point. I hadn't seen that usage before, so thank you for teaching me something new.

    One thing that seems to make a significant difference in how the variables are interpreted is whether or not the code is inside a function. If it's inside a function, then Dave's code using defined() should work. But if it's not inside a function, then the interpreter gets confused about the variables that don't exist and throws the error.

    Paul Grosso suggested to me offline to use an execute wrapper to defer variable substitution until execution time. So you could solve the problem either by embedding the code in a function and calling the function, or by adding execute to the source commands, like so:

    if(!defined($main::ENV['XPS3_HOME'])) {
    execute source $XPS3_HOME\XPSDocs\entities\notfound.acl
    } else {
    execute source $XPS_HOME\XPSDocs\entities\found.acl
    };

    Hope that helps clarify things.

    --Clay

    Clay Helberg
    Senior Consultant
    TerraXML
    1-Visitor
    September 27, 2011
    Exact Clay, we also often use (without always be obliged to):

    exec source $SIGMA/myscript.acl;

    Thanks for all your answers.

    Yves Deniard
    MBDA
    1 avenue Réaumur
    92358 Le Plessis-Robinson cedex
    France
    tél.:01.71.54.27.39
    yves.deniard@mbda-systems-com

    -----Message d'origine-----
    De : Clay Helberg [