惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

MoeShin

Alpine 下各语言的大小 - MoeShin 碧蓝档案日服模拟器体验 - MoeShin 域名邮箱记 - MoeShin Xposed Hook 替换类 - MoeShin XPosed Hook 子类重写的方法,并调用父方法 - MoeShin iOS iSH 笔记 - MoeShin Windows Terminal + MSYS2 + ZSH 配置 Cmder 修改 λ 标记 - MoeShin MAC IDEA 中 Git GPG 签名失败
PowerShell [ ] 转义 - MoeShin
作者: MoeShin · 2021-02-27 · via MoeShin

这波是玄学,没有找到相关文档,都是自己试出来的。。。

文件路径

首先,我们新建一个文件:

> New-Item '['

非常成功并没有报错,然后我们用 ls 查看一下文件:

> ls '['
Get-ChildItem : 无法检索 cmdlet 的动态参数。指定的通配符模式无效: [
所在位置 行:1 字符: 1
+ ls '['
+ ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem],ParameterBindingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetChildItemCommand

天哪,这是什么?试试按 TAB 键补全:

> ls '.\`['
ls : 找不到路径“C:\Users\MoeShin\test\`[”,因为该路径不存在。
所在位置 行:1 字符: 1
+ ls '.\`['
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\MoeShin\test\`[:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

这啊,又是什么?

后来,我试啊试啊,发现前面加两个反引号才行:

> ls '``['

    目录: C:\WDNMD

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         1202/23/66     66:66              0 [

所以,我们 ForEach-Object 遍历文件夹的时候就要处理一下,比如这样替换:

ls | ForEach-Object {
    ls ($_.name  -replace '(\[|\])', '``$1')
}

Remove-ItemProperty

这是我在搞注册表时发现的问题,-Name 只需要一个反引号就行