免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 17478 | 回复: 12
打印 上一主题 下一主题

为什么我的echo "\n"不换行?!?!?! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-30 16:46 |只看该作者 |倒序浏览
命令及显示结果如下:
[root@localhost bin]# FRUIT_BASKET="apple orange pear"
[root@localhost bin]# echo "Your fruit basket contains:\n$FRUIT_BASKET"
Your fruit basket contains:\napple orange pear

如下是我的set -o参数:
[root@localhost bin]# set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off

stty -a结果如下:
[root@localhost tmp]# stty -a
speed 38400 baud; rows 48; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

不知跟这两个里面的某项有没有关系,请大家帮帮忙,谢谢。

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
2 [报告]
发表于 2007-08-30 16:51 |只看该作者
\echo "Your fruit basket contains:\n$FRUIT_BASKET"
这样?

论坛徽章:
0
3 [报告]
发表于 2007-08-30 16:58 |只看该作者
yun
echo -e "Your fruit basket contains:\n$FRUIT_BASKET"

论坛徽章:
0
4 [报告]
发表于 2007-08-30 17:03 |只看该作者
咦?
为什么要加-e呢?不加不行啊!
让bash默认打开-e这项不行么?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
5 [报告]
发表于 2007-08-30 17:05 |只看该作者
原帖由 灿烂小猪 于 2007-8-30 17:03 发表
咦?
为什么要加-e呢?不加不行啊!
让bash默认打开-e这项不行么?

加个-e能累死呀! 嘿嘿嘿

论坛徽章:
0
6 [报告]
发表于 2007-08-30 17:13 |只看该作者
原帖由 寂寞烈火 于 2007-8-30 17:05 发表

加个-e能累死呀! 嘿嘿嘿



嗯,嗯。法王说得是!

加-e,加-e

论坛徽章:
0
7 [报告]
发表于 2007-08-30 17:18 |只看该作者
顺便问一下,为什么我的回贴加不上Smilies小图标呢?
咋回事?

论坛徽章:
0
8 [报告]
发表于 2007-08-31 14:10 |只看该作者

回复 #4 灿烂小猪 的帖子

alias echo='echo -e'

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
9 [报告]
发表于 2007-08-31 14:50 |只看该作者
原帖由 灿烂小猪 于 2007-8-30 17:18 发表
顺便问一下,为什么我的回贴加不上Smilies小图标呢?
咋回事?

这是论坛的问题, 你可以复制表情地址, 如:

  1. [img]http://bbs.chinaunix.net/images/smilies/icon_mrgreen.gif[/img]
复制代码

论坛徽章:
0
10 [报告]
发表于 2007-09-01 17:15 |只看该作者
shell 十三問
3) 別人 echo、你也 echo ,是問 echo 知多少?
http://bbs.chinaunix.net/viewthread.php?tid=218853&extra=&page=2#pid1467910

Learning the bash Shell - 2nd Edition (o'reilly)
Table 7.2. echo Options
Option
Function
-e
Turns on the interpretation of backslash-escaped characters
-E
Turns off the interpretation of backslash-escaped character on systems where this mode is the default
-n
Omit the final newline (same as the \c escape sequence)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP