gpt4 book ai didi

variables - 如何将变量的值用作变量本身?

转载 作者:行者123 更新时间:2023-12-03 00:53:46 25 4
gpt4 key购买 nike

我试图在需要的Powershell中编码,我使用变量的值作为变量本身;有适当的语法可以做到吗?

这是例子;

$color = "red"
$red = 1

how can i obtain the value of 1? $($color) $"$color" etc give out the errors.

如果需要,我可以就正在处理的问题进行更多说明。

最佳答案

语法不是很简洁,但是您可以使用 Get-Variable cmdlet:

Get-Variable -Name $color -ValueOnly

...或者干脆...
gv $color -ValueOnly

关于variables - 如何将变量的值用作变量本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13863660/

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