Tuesday, July 8, 2008

Don't Believe Everything You Read

I made a boo-boo on my previous post about importing scripts as libraries.  In researching the dotsource operator I picked up some misinformation.  My brain was nagging at me that I might have gotten the wrong information already, but my tests had seemed to be working.

The dotsource operator does not run the script in the global scope.  It creates all variables and functions in the current scope.  If you're running a script at the command-line then this has the effect of running the script in the global scope, but in my example profile I made a mistake.  Using the dotsource operator where I put it ends up creating the functions inside the scope of the scriptblock that it is called in, not the global scope.

As a temporary measure I made the scripts that I want to import create their functions in the global scope, but that's just a temporary condition, dig*?

How did I make that mistake?  I forgot that I had a script in my path with the same name as the function I thought I was importing, making it look like the script had imported the function into the global scope.


* Sorry, every once in a while I channel George Clinton when I type.

No comments: