为什么在执行以下脚本时每个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:)
答案 0 :(得分:4)
您只需要将换行符\n
添加到printf
语句中:
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
答案 1 :(得分:4)
printf
不会将换行符附加为标准行为,您需要将其添加到打印字符串中:
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT