作者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/m.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