曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4913|回复: 0
打印 上一主题 下一主题

echo --- 输出文本内容

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34397
跳转到指定楼层
楼主
发表于 2010-2-5 12:55:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1、-n 选项禁止 echo 换行,比较
cfgtest:/ # echo  "hello world"
hello world
cfgtest:/ # echo -n "hello world"
hello worldcfgtest:/ #

2、在 echo 中可以使用转义字符,其中常见的有下面几个:
\c   不换行
\f   进纸
\t   跳格
\n   换行
在 linux 中,使能转义字符需要使用 -e 选项,在 UNIX 里则不需要:
cfgtest:/ # echo -e "\thello world\t\t\t"
        hello world     
                       
        
又如:
cfgtest:/ # echo -e "\thello world\t\t\t"
        hello world
cfgtest:/ # echo -e "this echo's 3 new lines\n\n\n"; echo "OK"
this echo's 3 new lines


OK


3、> 和 >> 符号的区别
在 echo 中,用 > 符号把输出的内容导入到文件中,再使用一次 > 符号指向同一文件,则当前的内容会覆盖掉以前写入的内容。

>> 符号则不会覆盖,而是在文件的末尾“追加”,如
echo "hello world" > hello.txt
cfgtest:~ # echo "add it to the end at `date`" >> hello.txt
cfgtest:~ # cat hello.txt
hello world
add it to the end at ---  1 16:39:46 CST 2010


[table=958px][tr][td]

选项
含义
-e
允许解释下面列出的转义序列
-n
删除输出结果中行尾的换行符
-E
禁止解释这些转义字符,即使在那些默认解释他们的系统上(bash2.x)
转义序列
\a
报警()
\b
退格
\c
不带换行符打印一行
\f
换页
\n
换行
\r
回车
\t
制表符
\v
纵向制表符
\\
反斜杠
\nnn
ASCII码是nnn(八进制)的字符



[/td][/tr][/table]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-6-18 11:26 , Processed in 0.062477 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表