LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 653|回复: 3

我想在两个字符串变量中间加入换行符,总是不成功,请高人指点[已解决]

[复制链接]
发表于 2005-4-4 15:14:51 | 显示全部楼层 |阅读模式
  1. [root@localhost log]# a=abc
  2. [root@localhost log]# b=def
  3. [root@localhost log]# c="$a//n$b"
  4. [root@localhost log]# echo $c
  5. abc//ndef
  6. [root@localhost log]# c="$a/n$b"
  7. [root@localhost log]# echo $c
  8. abc/ndef
  9. [root@localhost log]# c="$a\n$b"
  10. [root@localhost log]# echo $c
  11. abc\ndef
  12. [root@localhost log]# c="$a\\n$b"
  13. [root@localhost log]# echo $c
  14. abc\ndef
  15. [root@localhost log]# c="$a/\n$b"
  16. [root@localhost log]# echo $c
  17. abc/\ndef
  18. [root@localhost log]# c="$a\/n$b"
  19. [root@localhost log]# echo $c
  20. abc\/ndef
  21. [root@localhost log]#
复制代码
发表于 2005-4-4 15:27:36 | 显示全部楼层
Post by lksj
  1. [root@localhost log]# a=abc
  2. [root@localhost log]# b=def
  3. [root@localhost log]# c="$a//n$b"
  4. [root@localhost log]# echo $c
  5. abc//ndef
  6. [root@localhost log]# c="$a/n$b"
  7. [root@localhost log]# echo $c
  8. abc/ndef
  9. [root@localhost log]# c="$a\n$b"
  10. [root@localhost log]# echo $c
  11. abc\ndef
  12. [root@localhost log]# c="$a\\n$b"
  13. [root@localhost log]# echo $c
  14. abc\ndef
  15. [root@localhost log]# c="$a/\n$b"
  16. [root@localhost log]# echo $c
  17. abc/\ndef
  18. [root@localhost log]# c="$a\/n$b"
  19. [root@localhost log]# echo $c
  20. abc\/ndef
  21. [root@localhost log]#
复制代码


呵呵,兄弟可是用穷举法啊 ;)

我来一个
  1. $ a=hello
  2. $ b=world
  3. $ echo $a
  4. hello
  5. $ echo $b
  6. world
  7. $ c="$a\n$b"
  8. $ echo $c
  9. hello\nworld
  10. $ echo -e $c
  11. hello
  12. world
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-4 15:36:51 | 显示全部楼层
噢,我知道了。。。
回复 支持 反对

使用道具 举报

发表于 2005-4-4 17:52:06 | 显示全部楼层
把双引号 全改成单引号.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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