开发者

How to evalute a string twice in Powershell

开发者 https://www.devze.com 2022-12-30 10:45 出处:网络
anyone know how to evalute a string twice in powershell? from example $l1 = yes $l2 = no for (i=0;i -lt 2; i++)开发者_如何转开发

anyone know how to evalute a string twice in powershell?

from example $l1 = yes $l2 = no

for (i=0;i -lt 2; i++)开发者_如何转开发 { echo $1$i }


If I understand the question correctly then this code may do the job:

$l1 = 'yes'
$l2 = 'no'

# make and evaluate the expression:
for ($i = 1; $i -le 2; $i++) {
    Invoke-Expression "`$l$i"
}

# or, to be embedded into a string:
for ($i = 1; $i -le 2; $i++) {
    @"
Value is: $(Invoke-Expression "`$l$i")
"@
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号