目前我正在编写一个小外壳(重定向、管道、执行等)。一直试图弄清楚 Linux shell 在解决 I/O 重定向方面采取的步骤。
关于我需要帮助的一些问题:
shell 在寻找重定向时从命令行读取的方向是什么?从左到右还是相反?使用递归?
shell需要查找哪些情况?(不确定是否有很多或只有一对可以包含很多变化)
无论如何,我能想到的一些是(如果我错了,请纠正我):
cmd > file1 # stdout of cmd goes to file
cmd file1 > file2 # stdout of cmd with file1 as an argument goes to file2
cmd file2 < file1 # stdin on file2 comes from file1
现在我不知道以下情况的过程(如外壳如何查找和处理这些)。我不知道外壳采取的步骤
cmd file2 > file3 < file1 # using "tee" in place of "cmd" I don't know
# how to do the dups and when to exec
cmd file2 < file3 > file1 # same ^