[英]cannot redirect stdin in bash
I am playing with file descriptors. 我在玩文件描述符。 A common practice is to redirect stdout and stderr using file descriptors, like this:
一种常见的做法是使用文件描述符重定向stdout和stderr,如下所示:
$ ls >files.txt 2>errors.txt
another example might be: 另一个示例可能是:
$ echo 'Hello there' > message.txt 2> errors.txt
however the following does not work: 但是以下方法不起作用:
$ echo 'Hello There' 0> input_message.txt > output_message.txt 2> errors.txt
It seems like the file descriptor 0 is not working as input_message.txt
is empty, I'd expect to find the text message Hello There
instead. 似乎文件描述符0无效,因为
input_message.txt
为空,我希望找到文本消息Hello There
来代替。
Why is that ? 这是为什么 ?
You use <
(or 0<
) to redirect stdin, like: 您可以使用
<
(或0<
)重定向标准输入,例如:
command <file
or: 要么:
command <&fd
where fd
is a file descriptor opened for reading. 其中
fd
是打开供读取的文件描述符。
As for your example, since echo
ignores stdin, this correction won't change the behavior. 对于您的示例,由于
echo
忽略stdin,因此此更正不会更改行为。
See Bash Reference Manual § 3.6 Redirections . 参见Bash参考手册§3.6重定向 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.