gpt4 book ai didi

powershell - PowerShell -and 条件运算符

转载 作者:行者123 更新时间:2023-12-03 05:47:46 27 4
gpt4 key购买 nike

要么我不理解 MSDN 上的文档,要么文档不正确。

if($user_sam -ne "" -and $user_case -ne "")
{
Write-Host "Waaay! Both vars have values!"
}
else
{
Write-Host "One or both of the vars are empty!"
}

我希望你能理解我想要输出的内容。我想填充 $user_sam 和 $user_case 以便访问第一个语句!

最佳答案

您可以将其简化为

if ($user_sam -and $user_case) {
...
}

因为空字符串强制为 $false (就此而言,$null 也是如此)。

关于powershell - PowerShell -and 条件运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9871867/

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