将数据从程序写入文件

发布于 2024-08-08 02:18:07 字数 192 浏览 2 评论 0原文

我正在使用Linux。假设我有一个名为 add 的程序。该程序需要两个数字。

所以如果我输入

add 1 2

答案是 3 //显而易见

什么命令会将其写入名为 add.data 的文件中,

我有点像 Linux n00b。我正在阅读有关管道的内容。谢谢。

I'm using linux. Let's say I have a program named add. The program takes two numbers.

so if I type in

add 1 2

the answer is 3 //obvious

what command will make this write out to a file named add.data

I'm kind of a linux n00b. I was reading about piping. Thanks.

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

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

发布评论

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

评论(3

一生独一 2024-08-15 02:18:07

管道意味着将程序的输出作为输入发送到第二个程序,第二个程序必须能够从标准输入读取数据,例如

add 1 2 | echo

您在这里询问的是输出重定向 :您应该使用

add 1 2 > add.data

输出创建一个新文件(如果存在,将被覆盖),并

add 1 2 >> add.data

创建一个新文件或附加到现有文件。

Piping means sending the output of a program as input to a second, which must be able to read data from the standard input, e.g.

add 1 2 | echo

What you are asking about here is output redirection: you should use

add 1 2 > add.data

to create a new file with your output (if existing will be overwritten), and

add 1 2 >> add.data

to create a new one or append to an existing.

唱一曲作罢 2024-08-15 02:18:07

添加 2 3 >某事.txt

add 2 3 > something.txt

笑着哭最痛 2024-08-15 02:18:07

这会将输出重定向到文件中,每次都重新创建该文件

add 1 2 > add.data

这将附加到文件末尾

add 1 2 >> add.data

This will redirect output into a file, recreates the file every time

add 1 2 > add.data

This will append to the end of the file

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