首页 > 其他 > 详细

echo/printf用法及区别

时间:2017-06-23 09:58:22      阅读:275      评论:0      收藏:0      [点我收藏+]

一、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

本文出自 “10858195” 博客,请务必保留此出处http://10868195.blog.51cto.com/10858195/1941160

echo/printf用法及区别

原文:http://10868195.blog.51cto.com/10858195/1941160

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!