Powershell:包含另一个包含包含的脚本? [英] Powershell: Include another script that has includes?
问题描述
我想在制作脚本时让我的生活更轻松.我正在盯着一个小框架,它将具有包含文件的层次结构.问题是点源 ps1 脚本已经有其他文件点源会限制原始调用脚本中的范围.它看起来像这样:
\config\loadvariables.ps1
$var = "shpc0001"
\config\config.ps1
<预><代码>.'.\loadvariables.ps1'\test.ps1
<预><代码>.'.\config\config.ps1'回声 $var问题在于 test.ps1
尝试加载 loadvariables.ps1
,因为它位于 test.ps1
脚本旁边.我该如何解决这个问题?
管理具有相互依赖关系的脚本集合的最简单方法是将它们转换为模块.此功能仅在 2.0 中可用,但它允许您将一组脚本分成具有声明依赖项的独立组件.
这是一个关于如何启动和运行模块的教程的链接
I want to make my life easier when making scripts. I'm staring a little framework that will have a hierarchy of include files. The problem is dot sourcing a ps1 script that already has other files dot sourced brakes the scope in the original calling scripts. It looks like this:
\config\loadvariables.ps1
$var = "shpc0001"
\config\config.ps1
. '.\loadvariables.ps1'
\test.ps1
. '.\config\config.ps1'
echo $var
The problem is that test.ps1
tries to load loadvariables.ps1
as it is located beside test.ps1
script.
How can I solve this?
The easiest way to manage a collection of scripts which have inter-dependencies is to convert them to modules. This feature is only available in 2.0 but it allows you to separate a group of scripts into independent components with declared dependencies.
Here is a link to a tutorial on getting modules up and running
这篇关于Powershell:包含另一个包含包含的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!