Question:
In my main script, I will first call an init function to initiate many variables which I expected to be used in the script. One way is to use variables whose name are like $script:var1
which are script level variable. But that’s kind of ugly and I’d like to use normal variable name, so I need a mechanism to source a function just like source a file.
When source a file, all the variables in that file are available in the calling script.
Answer:
Use the same syntax that uses dot-operator, just like for sourcing files:
1 2 |
. My-Function |