码迷,mamicode.com
首页 > 系统相关 > 详细

Shell echo命令

时间:2019-06-28 00:51:03      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:shell   字符   指令   name   输出   转义字符   date   char   执行   

echo是Shell的一个内部指令,用于在屏幕上打印出指定的字符串。命令格式:

  1. echo arg

您可以使用echo实现更复杂的输出格式控制。

显示转义字符

  1. echo "\"It is a test\""

结果将是:
"It is a test"

双引号也可以省略。

显示变量

  1. name="OK"
  2. echo "$name It is a test"

结果将是:
OK It is a test

同样双引号也可以省略。

如果变量与其它字符相连的话,需要使用大括号({ }):

  1. mouth=8
  2. echo "${mouth}-1-2009"

结果将是:
8-1-2009

显示换行

  1. echo "OK!\n"
  2. echo "It is a test"

输出:
OK!
It is a test

显示不换行

  1. echo "OK!\c"
  2. echo "It is a test"

输出:
OK!It si a test

显示结果重定向至文件

  1. echo "It is a test" > myfile

原样输出字符串

若需要原样输出字符串(不进行转义),请使用单引号。例如:

  1. echo ‘$name\"

显示命令执行结果

  1. echo `date`

结果将显示当前日期

从上面可看出,双引号可有可无,单引号主要用在原样输出中。

Shell echo命令

标签:shell   字符   指令   name   输出   转义字符   date   char   执行   

原文地址:https://www.cnblogs.com/chengkanghua/p/11100295.html

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