Echo newline in Bash prints literal \n
In Bash, tried this:
echo -e "hellonworld"
 But it doesn't print a newline, only n .  How can I make it print the newline?  
I'm using Ubuntu 11.04.
 You could use printf instead:  
printf "hellonworldn"
 printf has more consistent behavior than echo .  The behavior of echo varies greatly between different versions.  
Are you sure you are in bash? Works for me, all three ways:
echo -e "Hellonworld"
echo -e 'Hellonworld'
echo Hello$'n'world
echo $'hellonworld'
prints
hello
world
 $'' strings use ANSI C Quoting:  
 Words of the form $'string' are treated specially.  The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.  
上一篇: 如何解析shell脚本中的符号链接
下一篇: Echo换行符在Bash中打印文字\ n
