私はPowerShellを学習し、"Read-Host -Prompt"と "Read-Host"に違いはありますか?
Read-Host -Prompt "Text"
と
Read-Host "Text"
それは同じものですか、私は見ていない午前差があるとの違いを知りたいですか?
私はPowerShellを学習し、"Read-Host -Prompt"と "Read-Host"に違いはありますか?
Read-Host -Prompt "Text"
と
Read-Host "Text"
それは同じものですか、私は見ていない午前差があるとの違いを知りたいですか?
それは同じことです。ここで起こっていることは、パラメータが(時には、通常は)名前付きか位置的に使用できることです。
この場合、まだ-Prompt
パラメータの値を指定していますが、具体的に名前で参照しているわけではありません。これが起こっていることを確認するには
ファンシーな方法はTrace-Command
コマンドレットである:
Trace-Command -Name ParameterBinding -Expression { Read-Host "Hello" } -PSHost
出力:
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Read-Host] DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Read-Host] DEBUG: ParameterBinding Information: 0 : BIND REMAININGARGUMENTS cmd line args to param: [Prompt] DEBUG: ParameterBinding Information: 0 : BIND arg [System.Collections.Generic.List`1[System.Object]] to parameter [Prompt] DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.Object] DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed. DEBUG: ParameterBinding Information: 0 : BIND arg [System.Collections.Generic.List`1[System.Object]] to param [Prompt] SUCCESSFUL DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Read-Host] DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing Hello: hi DEBUG: ParameterBinding Information: 0 : CALLING EndProcessing hi
Read-Host
のヘルプテキストは、構文図を示します:
PS> help Read-Host
Read-Host [[-Prompt] <Object>] [-AsSecureString]
[-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable <System.Stringr>] [<CommonParameters>]
...
これらの構文図を読むべきかの完全な説明は、(help about_Command_Syntax
を参照してください。)内蔵のヘルプから入手可能である。適切な部分は次のとおりです。
-- Brackets ([ ]) indicate optional items. A parameter and its value can be optional, or the name of a required parameter can be optional.
-Prompt
引数の場合、パラメータとの両方の値はオプションです。
++偉大な教師と人間の魚の答え。 – mklement0