gpt4 book ai didi

powershell - 使用另一个脚本中定义的枚举

转载 作者:行者123 更新时间:2023-12-02 23:41:51 24 4
gpt4 key购买 nike

我如何定义一个全局枚举以在定义的范围之外使用它?我创建了一个导入另一个脚本的脚本(包括所有全局函数、变量和枚举)

Enum CrudFlag
{
Undefined
Create
Read
Update
Delete
}

最佳答案

您必须使用dotsourceing 导入您的脚本:

Each script runs in its own scope. The functions, variables, aliases, and drives that are created in the script exist only in the script scope. You cannot access these items or their values in the scope in which the script runs.

To run a script in a different scope, you can specify a scope, such as Global or Local, or you can dot source the script.

The dot sourcing feature lets you run a script in the current scope instead of in the script scope. When you run a script that is dot sourced, the commands in the script run as though you had typed them at the command prompt. The functions, variables, aliases, and drives that the script creates are created in the scope in which you are working. After the script runs, you can use the created items and access their values in your session.

To dot source a script, type a dot (.) and a space before the script path

Source.

关于powershell - 使用另一个脚本中定义的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39719297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com