[问题] 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