Grrr ... Noob問題在這裏。我想創建一個塊,基本上這樣做:按X退出或其他任何鍵繼續?
Write-Host "Press X to cancel or any other key to continue"
$continue = Read-Host
If ($continue = "X")
{exit}
else
{Write-Host "Hello world"}
即使我按另一個鍵仍然退出...我做錯了什麼?謝謝!!!
Grrr ... Noob問題在這裏。我想創建一個塊,基本上這樣做:按X退出或其他任何鍵繼續?
Write-Host "Press X to cancel or any other key to continue"
$continue = Read-Host
If ($continue = "X")
{exit}
else
{Write-Host "Hello world"}
即使我按另一個鍵仍然退出...我做錯了什麼?謝謝!!!
您應該使用「-eq」進行比較。簡單的例子:
$a = "Powershell"
IF ($a -eq "PowerShell")
{
"Statement is True"
}
ELSE
{
"Statement is False"
}
下面是一些閱讀有信心以 「IF-THEN-ELSE」 語句:IF_THEN_ELSE in Powershell
=
運營商是分配。使用-eq
來測試是否相等。
明白了...謝謝!我知道我很親密。 :) – 2013-03-01 22:15:19
謝謝! -eq與「=」是問題。 – 2013-03-01 22:29:46