[問題] PowerShell逃脫字元問題

作者: falcon (falken)   2020-10-27 19:53:14
作業系統: Windows 10
Service Pack: 20H2
發生問題頻率: 100%
是否有做Windows Update: 有
問題內容:
據我所知Powershell中要表示
字元` = '``' = "````"
字元' = '''' = "`'"
字元[ = '`[' = "``["
字元] = '`]' = "``]"
依此類推...
# D:\`[test`]'`
test-path 'D:\```[test```]''``'
test-path "D:\``````[test``````]`'````"
# E:\`[test`]'``
test-path 'E:\```[test```]''````'
test-path "E:\``````[test``````]`'````````"
以上皆如預期回傳 True
# D:\`[test`]'`
test-path 'D:\```[test```]''`'
test-path "D:\``````[test``````]`'``"
# E:\`[test`]'``
test-path 'E:\```[test```]''```'
test-path "E:\``````[test``````]`'``````"
上面這些怎麼也全都回傳 True?
單引號內右側少了1個`
雙引號內右側少了2個`
想了一下...
看起來'`'或"``"右側沒有跟其他特殊字元相鄰時等同'``'或"````"
所以test-path中 '`' = '``' = "````" = "``````" = "````````"
怎麼會有這麼奇怪的行為? 還是我哪裡誤會了?
作者: Tabrith (血糖瑪琪朵)   2020-11-13 03:08:00
遇到引號建議使用 Test-Path -LiteralPath

Links booklink

Contact Us: admin [ a t ] ucptt.com