如何防止ZSH逃脱了争论中的后斜线以命令?

发布于 2025-01-23 07:33:23 字数 360 浏览 0 评论 0原文

我在 zsh 中键入此行以找到一个后斜切,然后是小写n:
pdfgrep“ \\ n”<一些路径>
(ps pdfgrep ,在pdfs上进行grep)

然后 zsh 将首先逃脱单个后背Backsslash,导致 pdfgrep 请参见“ \ n”< soming path>,即搜索线feed(lf)。

如何防止 zsh 第一次逃脱命令中的反斜杠?

I type this line in zsh to find a backslash followed by a lowercase n:
pdfgrep "\\n" <some path>
(P.S. pdfgrep, doing grep on PDFs)

Then zsh will first escape double backslash into a single backslash, resulting in what pdfgrep see is "\n" <some path>, i.e. searching for a line feed (LF).

How to prevent zsh from first escaping backslash in arguments to command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2025-01-30 07:33:23

您好,希望您一切都好,

谢谢您的问题,我不知道PDFGREP:P

首先,我下载了PDF(这完全 https://www.docker.com/wp-content/uploads/2022/03/docker-cheat-cheat-cheat-sheat-sheet.pdf

然后我尝试了简单:

❯ pdfgrep '\n' docker-cheat-sheet.pdf

但是您不知道。

然后像你一样,我尝试了这一点:

pdfgrep '\\n' docker-cheat-sheet.pdf

但是没有输出。

我决定尝试使用回声命令逃脱\ n进行测试:

正如预期的那样,这解释了\ n:

❯ echo -e "test\ntest"
test
test

然后我尝试了此操作,但它也没有起作用:

❯ echo -e "test\\ntest"
test
test

然后我尝试了此操作,它与echo命令一起使用

❯ echo -e "test\\\ntest"
test\ntest

:我决定在PDF上尝试它,但仍然没有输出:

❯ pdfgrep '\\\n' docker-cheat-sheet.pdf

然后,我找到了这个主题: PDFGREP模式要包含/排除线路破坏

并尝试过:

❯ pdfgrep -P '\n' docker-cheat-sheet.pdf

我认为这可以完成工作,是您想要的吗?

Bguess

hello, hope you are doing well,

Thank you for your question, I didnt know pdfgrep :p

First, I downloaded a pdf (this one exactly https://www.docker.com/wp-content/uploads/2022/03/docker-cheat-sheet.pdf)

then I tried the simple:

❯ pdfgrep '\n' docker-cheat-sheet.pdf

but didnt work as you know.

Then like you, I tried this:

pdfgrep '\\n' docker-cheat-sheet.pdf

but there was no output.

I decided to try to escape the \n with an echo command to test:

as expected, this interprete the \n:

❯ echo -e "test\ntest"
test
test

then I tried this, but it didnt work also:

❯ echo -e "test\\ntest"
test
test

then I tried this, and it worked with the echo command:

❯ echo -e "test\\\ntest"
test\ntest

So i decided to try it on the pdf, but still no output:

❯ pdfgrep '\\\n' docker-cheat-sheet.pdf

then, I have found this topic: pdfgrep pattern to include/exclude linebreak

and tried this:

❯ pdfgrep -P '\n' docker-cheat-sheet.pdf

I think this do the job, is it what you was looking for?

bguess

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文