我試圖了解輸入重定向是如何作業的,以便我可以在我正在構建的 shell 中模擬它。假設我們創建了 3 個檔案:
echo this is test 1 > test1
echo this is test 2 > test2
echo this is test 3 > test3
然后我們嘗試使用類似的命令重定向輸入和輸出cat test1 > test2 < test 3。test2 的內容將變為:this is a test1. 我希望它們成為,this is a test 3因為這是最后一次“操作”。我怎么了?先感謝您!
PS 如果您能指導我在使用上述復雜命令時重定向如何作業的指南,我將不勝感激!
uj5u.com熱心網友回復:
cat除非這些引數之一指定了標準輸入,否則當它具有非選項引數時不從標準輸入讀取。在您提供的示例中cat test1 > test2 < test3,該檔案test3是 的輸入流cat,但cat由于您沒有指定-為引數而忽略了它。如果你不是做cat test1 - > test2 < test3,然后cat將讀取其標準輸入,但最終內容test2不會僅僅是內容test3,但的串聯test1和test3。
也許您應該嘗試以下實驗:
cat test1 - > test2 < test3
cat > test2 < test3
cat - test1 - > test2 < test3
cat - - test1 test1 > test2 < test3
另外,也許看看
< test3 cat > test2
cat < test3 - test1 > test2
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/378365.html
