开发者

How to evalute a string twice in Powershell

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜