Linux:如何正确地将文本传输到程序中?

发布于 2024-08-20 04:27:42 字数 474 浏览 11 评论 0原文

我看过但找不到任何东西。例如,我使用的 TTS 程序可让您执行以下操作:

~#festival -tts | echo "I am to be spoken"

这确实很好,但对于我使用的程序(例如 hexdump),我不知道如何将文本通过管道传输到其中。我真的可以使用其中一些东西,我尝试过(但失败)的一些例子如下:

~#gtextpad < dmesg
      //(how do I put the contents into the text pad for display? not just into a file)
~#hexdump | echo "I am to be put into hexdump"
      //(How do I get hexdump to read the echo? It normally reads a file such as foo.txt..)

I've looked but can't find anything. A program for example, a TTS I use lets you do the following:

~#festival -tts | echo "I am to be spoken"

Which is really nice, but for programs I use such as hexdump, I don't know how to pipe text into it. I can REALLY use some of these things, some examples I tried (but failed) are like so:

~#gtextpad < dmesg
      //(how do I put the contents into the text pad for display? not just into a file)
~#hexdump | echo "I am to be put into hexdump"
      //(How do I get hexdump to read the echo? It normally reads a file such as foo.txt..)

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

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

发布评论

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

评论(4

请叫√我孤独 2024-08-27 04:27:43

以下是将文本传递到 hexdump

Stdin 的一些方法:

echo "text" | hexdump

这里

hexdump <<EOF
text
EOF

处理整个文件的文档

hexdump file

here are some ways to pass text to hexdump

Stdin:

echo "text" | hexdump

Here document

hexdump <<EOF
text
EOF

to process entire file

hexdump file
奢欲 2024-08-27 04:27:43

在 bash 上,你也可以这样做

hexdump <<< "Pipe this text into hexdump"

On bash, you can also do

hexdump <<< "Pipe this text into hexdump"
云醉月微眠 2024-08-27 04:27:43

管道(由管道符号分隔的一系列命令)中的数据流从左向右流动。因此,下面 command1 的输出将转到 command2 的输入,依此类推。

command1 |
command2 |
command3 arg1 arg2 arg3 |
sort |
more

因此,要将“echo”的输出获取到“hexdump”中,请使用:

echo "I am to be dumped" | hexdump

我不知道您显示的“festival”命令如何工作。 shell 做了足够多的管道工作,没有做出无根据的假设和大量的欺骗,然后仍然依赖内核中的调度决策来让事情变得“正确”,我不知道如何让它工作。

The data flow in a pipeline (series of commands separated by pipe symbols) flows from left to right. Thus, the output from command1 below goes to the input of command2, and so on.

command1 |
command2 |
command3 arg1 arg2 arg3 |
sort |
more

So, to get the output of 'echo' into 'hexdump', use:

echo "I am to be dumped" | hexdump

I don't see how the 'festival' command you show can work. The shell does enough plumbing that without making unwarranted assumptions and doing a lot of skulduggery and then still relying on scheduling decisions in the kernel to get things 'right', I don't see how it can be made to work.

江湖正好 2024-08-27 04:27:43

来自 hexdump(1) 手册页:

hexdump 实用程序是一个过滤器,它以用户指定的格式显示指定的文件或标准输入(如果未指定文件)。

所以:

echo "I am to be put into hexdump" | hexdump

From the hexdump(1) man page:

The hexdump utility is a filter which displays the specified files, or the standard input, if no files are specified, in a user specified format.

So:

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