gpt4 book ai didi

powershell - 在其他变量名中使用变量

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

我需要这些变量名称由另一个变量的值连接的变量值。

例如

$GV_R32_var = "testtesttest"
$m = "R32"
(Get-Variable -Name "`$GV_$($m)_var").Value

我收到以下错误消息:

+(获取变量-名称“`$ GV _ $($ m)_var”)。值
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:ObjectNotFound:($ GV_R32_var:String)[Get-Variable],ItemNotFoundException
+ FullyQualifiedErrorId:VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand

最佳答案

你真的很亲密!

变量名称不包含美元!

所以你的代码:

(Get-Variable -Name "`$GV_$($m)_var").Value

成为:
(Get-Variable -Name "GV_$($m)_var").Value

关于powershell - 在其他变量名中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48185639/

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