Linux的命令暧昧重定向 [英] Linux command ambiguous redirect

查看:152
本文介绍了Linux的命令暧昧重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个实验室叫做头和header.txt我想猫进我的3个C文件
猫../header.txt>找到-name的* .c

Hi I have a lab header called header.txt and I want to cat into my 3 C files cat ../header.txt > find -name *.c

什么是错的上述声明?

推荐答案

在I / O重定向操作符< > 等方面都只能采取的一个字的当作它们的参数,并使用它作为一个的文件名的。还有什么别的被认为是命令行的一部分。

The I/O redirection operators <, >, etc. all only take one word as their argument, and use that as a filename. Anything else is considered part of the command line.

所以,当你运行这样的:

So when you run this:

cat ../header.txt > find -name *.c

这是完全一样的:

It's exactly the same as this:

cat ../header.txt -name *.c > find

这可能不会做任何有用的事情。

That's probably not going to do anything useful.

另外一个问题:你的 * C 未逃脱或引用,这样的bash将扩大它,而不是将它传递给找到

Another problem: your *.c isn't escaped or quoted, so bash will expand it rather than passing it to find.

您可以做你仿佛想用 T恤,它接受任意数量的参数:

You can do what you seem to want with tee, which accepts any number of arguments:

cat ../header.txt | tee *.c

然后你甚至不需要更多的,真的。

tee *.c < ../header.txt

当然,你也可以同样用 CP 做到这一点。也许你的意思的追加的这些文件?如果是这样,通 -a T恤以及

Of course, you could just as well do this with cp. Perhaps you meant to append to these files? If so, pass -a to tee as well.

有趣的花絮:zsh的和其他一些贝壳会让你有多个&GT; 运营商,它的工作原理就像三通。 (多&LT; 也是允许的,就像

Interesting trivia: zsh and some other shells will let you have multiple > operators, which works just like tee. (Multiple < is also allowed and works like cat.)

cat infile > outfile1 > outfile2

但是你要真正列出每一个单独的文件,所以你不能用这个快捷方式中包含 A水珠*。ç

这篇关于Linux的命令暧昧重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆