简体   繁体   English

循环中BASH中的echo / printf没有换行符

[英]no newline in echo/printf in BASH while loop

why on executing following script each printf (tried also with echo) is printed on the same line?? 为什么在执行以下脚本时每个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
}

Now, this produces a single line output: 现在,这会产生一个单行输出:

(entity:content member:)(entity:content name:id)(entity:content /name:)

How do I change this to multiline, like: 如何将其更改为多行,例如:

(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM