[英]no newline in echo/printf in BASH while loop
為什么在執行以下腳本時每個printf(也嘗試使用echo)打印在同一行?
function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | \
{ while read_dom; do
printf "(entity:content %s:%s)" $ENTITY $CONTENT
}
現在,這會產生一個單行輸出:
(entity:content member:)(entity:content name:id)(entity:content /name:)
如何將其更改為多行,例如:
(entity:content member:)
(entity:content name:id)
(entity:content /name:)
您只需要在printf
語句中添加換行符\\n
:
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
printf
不會將換行符附加為標准行為,您需要將其添加到打印字符串中:
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.