|
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] |
|