简体   繁体   English

Shell STDIN重定向三个反引号

[英]Shell STDIN redirection of three backticks

Motivation 动机

I have a Markdown backtick codeblock and I would like to insert it into a list item. 我有一个Markdown反引号代码块,我想将它插入列表项。 I tried using awk with STDIN redirection for fun. 我尝试使用带有STDIN重定向的awk来获得乐趣。 I ran into the following problem. 我遇到了以下问题。

Problem 问题

I adapted from Tutorials Point 's example to count the number of lines of a Markdown codeblock. 我改编自Tutorials Point的例子来计算Markdown代码块的行数。

$ wc -l << EOF
```
codeblock
```
EOF
  • Expected output: 3 预期产量: 3
  • Actual output: 实际产量:

     zsh: command not found: codeblock 1 

How to get the shell parse an odd number of backticks in STDIN? 如何让shell在STDIN中解析奇数个反引号?

Thanks for reading. 谢谢阅读。

Backticks are for command substitution , and command substitutions are expanded in here documents . 反引号用于命令替换 ,命令替换在这里扩展。 You should either quote EOF -this will disable all expansions-, or escape those backticks. 你应该引用EOF - 这将禁用所有扩展 - 或者逃避那些反引号。

$ wc -l << 'EOF'
```
codeblock
```
EOF

3
$ 
$ wc -l << EOF 
\`\`\`
codeblock
\`\`\`
EOF

3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM