作者falcon (falken)
看板Windows
标题[问题] PowerShell逃脱字元问题
时间Tue Oct 27 19:53:14 2020
作业系统: 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中 '`' = '``' = "````" = "``````" = "````````"
怎麽会有这麽奇怪的行为? 还是我哪里误会了?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 27.52.102.237 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Windows/M.1603799596.A.AC5.html
※ 编辑: falcon (27.52.102.237 台湾), 10/28/2020 01:27:57
1F:推 Tabrith: 遇到引号建议使用 Test-Path -LiteralPath 11/13 03:08