一、echo 用法:直接显示输入的内容。
例: #echo -e "the year is 2016. \n today is 7."
the year is 2016.
today is 7.
二、printf 用法:格式并显示输入的内容。
例:#printf "The year is 2016.\nToday is 7.\n"
The year is 2016.
Today is 7.
三、区别:
(1)首先echo是回显,即代表回车显示,是自带换行的;而printf只是打印出来,没有换行
(2)echo只是回显没有变量替换功能;printf是有的
举例:假如我们定义好变量a='hello world'
则 echo "%s" $a 显示的结果就是%s
而 printf "%s\n" $a 显示的结果就是hello world
转载于:https://blog.51cto.com/10868195/1941160