有助于理解 bash 重定向的正确思维模型是什么?

问题描述 投票:0回答:1

对导致以下 bash 会话日志的机制的一致解释是什么,有助于获得理解并对类似构建的命令的结果进行可靠的预测:

~ $ cat f
abc123
~ $ cat g
cat: g: No such file or directory
~ $ cat f g 2>&1 >h
cat: g: No such file or directory
~ $ cat h
abc123

~ $ cmd >a 2>&1
~ $ cat a
Command 'cmd' not found, but there are 19 similar ones.
~ $ cmd 2>&1 >a
Command 'cmd' not found, but there are 19 similar ones.
~ $ cat a
~ $  

bash shell io-redirection
1个回答
0
投票

有助于理解 bash 重定向的正确思维模型是什么?

当我阅读这些评论时,我猜你会感到困惑,因为“文件描述符”不是文件,而是真正指向文件句柄的指针。 文件描述符的“心理模型”在很多地方都有解释,甚至在 wiki 上也有解释

https://en.wikipedia.org/wiki/File_descriptor

。文件描述符是指向 inode 表的 filetable 的指针(类似于双指针)。

© www.soinside.com 2019 - 2024. All rights reserved.