开发者

Linux: How would I pipe text into a program properly?

开发者 https://www.devze.com 2022-12-19 16:21 出处:网络
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\"

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 pa开发者_如何学Pythond 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..)


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


On bash, you can also do

hexdump <<< "Pipe this text into hexdump"


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号