Mic*_*ter 12 powershell command-line
我知道分号是 Powershell 中的命令分隔符。 echo "hello"; dir
给出这个输出。
PS C:\> echo "hello"; dir
hello
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2018-04-29 13:02 BCD_Backup
d----- 2018-12-02 14:08 Dell
<snip>
Run Code Online (Sandbox Code Playgroud)
但是为什么会date; dir
给出这个输出呢?
PS C:\> date; dir
Friday, December 14, 2018 11:14:23
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\BCD_Backup
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName : BCD_Backup
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : True
Name : BCD_Backup
FullName : C:\BCD_Backup
Parent :
Exists : True
Root : C:\
Extension :
CreationTime : 2018-04-29 13:02:31
CreationTimeUtc : 2018-04-29 11:02:31
LastAccessTime : 2018-04-29 13:02:31
LastAccessTimeUtc : 2018-04-29 11:02:31
LastWriteTime : 2018-04-29 13:02:31
LastWriteTimeUtc : 2018-04-29 11:02:31
Attributes : Directory
Mode : d-----
BaseName : BCD_Backup
Target : {}
LinkType :
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Dell
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
<snip>
Run Code Online (Sandbox Code Playgroud)
\n\nPowerShell 自动添加
\nOut-Default
到每个管道的末尾\xe2\x80\xa6
当然,分号本身不足以识别这样的状态:
\nGet-Alias -Name gal; Get-Location\n
Run Code Online (Sandbox Code Playgroud)\n\n\nRun Code Online (Sandbox Code Playgroud)\nCommandType Name Version Source\n----------- ---- ------- ------\nAlias gal -> Get-Alias\n\nDrive : D\nProvider : Microsoft.PowerShell.Core\\FileSystem\nProviderPath : D:\\PShell\nPath : D:\\PShell\n
添加Out-Default
到管道显式解决了问题:
Get-Alias -Name gal | Out-Default; Get-Location\n
Run Code Online (Sandbox Code Playgroud)\n\n\nRun Code Online (Sandbox Code Playgroud)\nCommandType Name Version Source\n----------- ---- ------- ------\nAlias gal -> Get-Alias\n\n\nPath\n----\nD:\\PShell\n
归档时间: |
|
查看次数: |
3906 次 |
最近记录: |