[英]Looping through output of docker bash command
我試圖循環這樣一個 docker bash 命令: sudo docker exec -it my-container bash -c "cd sites && ls" > output.txt
這給了我預期的輸出,當我循環它時: cat output.txt | while read line do echo "abcd${line}def"; done
cat output.txt | while read line do echo "abcd${line}def"; done
cat output.txt | while read line do echo "abcd${line}def"; done
它給了我輸出:
defdfile1
defdfile2
簡而言之,它在文件名后重疊如果我在沒有 docker 命令的情況下執行所有這些操作,例如在我的主機上僅使用 ls 它可以正常工作,如何解決此問題?
當使用-t
標志 docker 輸出到標准輸出時,添加回車符。 它用cat -vte output.txt
顯示為^M
。 ( -v
, --show-nonprinting
使用 ^ 或 M- 符號顯示非打印字符)
此回車符會破壞格式,並且未正確處理行。 從命令中刪除-t
標志以獲得正確的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.