在包含与号 (&) 的 PowerShell 中设置位置
Set Location in PowerShell that contains a ampersand (&)
如何使用 PowerShell 将我的目录设置到以下位置?
W:\B&M\Store Segmentation\Pete\Python
我尝试使用:
PS > Set-Location -Path W:\B"&"M\Store Segmentation\Pete\Python
使用"
双引号或'
撇号如下:
Set-Location -Path "W:\B&M\Store Segmentation\Pete\Python"
或
Set-Location -Path 'W:\B&M\Store Segmentation\Pete\Python'
阅读 About Quoting Rules 了解解释。
虽然使用 "
或 '
完全是一个更好的主意,但应告知 PowerShell 转义字符:
`
使用这个caracher,可以对特殊字符进行scape,例如:
Set-Location C:\A`&B
例如在文件夹名称包含 []
:
的情况下您需要它
Set-Location 'C:\A&B[1]' # Will Fail
Set-Location 'C:\A&B`[1`]' # Correct
如何使用 PowerShell 将我的目录设置到以下位置?
W:\B&M\Store Segmentation\Pete\Python
我尝试使用:
PS > Set-Location -Path W:\B"&"M\Store Segmentation\Pete\Python
使用"
双引号或'
撇号如下:
Set-Location -Path "W:\B&M\Store Segmentation\Pete\Python"
或
Set-Location -Path 'W:\B&M\Store Segmentation\Pete\Python'
阅读 About Quoting Rules 了解解释。
虽然使用 "
或 '
完全是一个更好的主意,但应告知 PowerShell 转义字符:
`
使用这个caracher,可以对特殊字符进行scape,例如:
Set-Location C:\A`&B
例如在文件夹名称包含 []
:
Set-Location 'C:\A&B[1]' # Will Fail
Set-Location 'C:\A&B`[1`]' # Correct