0
在腳本中,我想逐行讀取一個過程輸出,並從用戶那裏獲得確認。到目前爲止,我已經做到了這一點:在流水線讀取循環中讀取鍵盤輸入
mycommand-outputpiped | while (read line)
do
read line
#dostuff
read confirm #oops -> this read the next item from the pipe, not the keyboard
done
於是,我就補充:
read confirm < /dev/stdin
但它並沒有改變的東西,它仍然讀取管道下一行... 我該如何處理?
不相關,但爲什麼在條件列表和循環體中爲變量'line'都有'read'命令? – chepner 2013-03-05 17:33:49
我不確定 - 我相信第一次檢查時仍有數據要讀取,而第二次讀取數據。我不知道如何清理它 – bagage 2013-03-05 17:35:11