使用 Bash 重定向到多个文件时重定向不明确
$ echo "" > /home/jem/rep_0[1-3]/logs/SystemOut.log
bash: /home/jem/rep_0[1-3]/logs/SystemOut.log: ambiguous redirect
我可以一次重定向到多个文件吗?
编辑:任何允许使用不明确的文件引用的答案?
$ echo "" > /home/jem/rep_0[1-3]/logs/SystemOut.log
bash: /home/jem/rep_0[1-3]/logs/SystemOut.log: ambiguous redirect
Can I redirect to multiple files at a time?
Edit: Any answer that allows use of the ambiguous file reference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这就是 tee 的用途:
tee 还输出到 stdout,因此您可能希望在重定向后放置一个文件(如上所示),或者将 stdout 发送到
/dev/null
。对于你的情况:
That's what tee is for:
tee also outputs to stdout, so you may want either to put one file after a redirect (as shown above), or send stdout to
/dev/null
.For your case:
您可以使用
tee
来执行此操作,其内容为从标准输入写入标准输出和文件。由于tee
也输出到 stdout,因此我选择将其输出定向到/dev/null
。请注意,bash 扩展与现有文件匹配,因此在执行此命令之前,您尝试写入的文件必须存在。附带说明一下,您传递给
echo
的""
是多余的。与您的问题不直接相关,但如果您不依赖 bash 扩展,您可以拥有多个管道。
You can do this using
tee
, which reads from stdin and writes to stdout and files. Sincetee
also outputs to stdout, I've chosen to direct it's output to/dev/null
. Note that bash expansion matches against the existing files, so the files you're trying to write to must exist before executing this command for it to work.As a side note, the
""
you pass toecho
is redundant.Not directly relevant to your question, but if you don't rely on bash expansion you can have multiple pipes.
我有同样的问题,只是想添加带有通配符的示例,因为它尚未显示。我想这就是您正在寻找的:
I had this same question and just wanted to add the example with the wildcard since it hadn't been shown. I think this is what you were looking for:
您可以这样做:
要禁止输出到 stdout,请将其添加到上面命令的末尾:
问题中的
echo
命令(不需要空引号)只需在文件。如果您想创建空文件,请使用touch
命令。You can do this:
To suppress the output to stdout, add this to the end of the commands above:
The
echo
command in your question (which doesn't require the empty quotes) simply puts a newline in the files. If you want to create empty files, use thetouch
command.不。使用
tee
两次怎么样?No. What about using
tee
twice?管道到“tee”命令以分支到文件并 std 输出,级联 tee 命令
Pipe to the "tee" command to branch to a file and std out, the cascade the tee commands