码迷,mamicode.com
首页 > 其他好文 > 详细

echo/printf用法及区别

时间:2017-06-23 10:38:09      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:hello   echo/printf用法及区别   world   

一、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用法及区别

标签:hello   echo/printf用法及区别   world   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!