免费注册 查看新帖 |

Chinaunix

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

关于I/O重定向的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-02 22:34 |只看该作者 |倒序浏览
想问下 <<的几个问题

cat <<END
cat <<\END
cat <<-END

之间的区别

谢谢

论坛徽章:
0
2 [报告]
发表于 2009-02-02 22:40 |只看该作者
不懂,好像结果是样的,等高手来

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
3 [报告]
发表于 2009-02-02 22:54 |只看该作者
[quote]
   Here Documents
       This type of redirection instructs the shell to  read  input  from  the
       current  source  until  a  line  containing only word (with no trailing
       blanks) is seen.  All of the lines read up to that point are then  used
       as the standard input for a command.

       The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

       No  parameter expansion, command substitution, arithmetic expansion, or
       pathname expansion is performed on word.  If any characters in word are
       quoted,  the  delimiter is the result of quote removal on word, and the
       lines in the here-document are not expanded.  If word is unquoted,  all
       lines  of  the here-document are subjected to parameter expansion, com&acirc;

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
4 [报告]
发表于 2009-02-02 23:12 |只看该作者
cat <<\END不进行变量代换等

  1. $a=123
  2. $ cat <<END
  3. > $a
  4. > END
  5. 123
  6. $ cat <<\END
  7. > $a
  8. > END
  9. $a
复制代码

论坛徽章:
0
5 [报告]
发表于 2009-02-02 23:52 |只看该作者
谢谢两们DX的指导!
andy的看明白了,也知道看出些作用了,
cjaizss  的似明非明,在man bash里也找到了这段,示例试过,但不知其作用

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
6 [报告]
发表于 2009-02-03 00:31 |只看该作者
原帖由 haimming 于 2009-2-2 23:52 发表
谢谢两们DX的指导!
andy的看明白了,也知道看出些作用了,
cjaizss  的似明非明,在man bash里也找到了这段,示例试过,但不知其作用

<<-END
带-时,内容及结束标记前的tab会自动去掉。

  1. #!/bin/bash
  2. cat <<-end
  3. test
  4.         end  #这个就是结束标记(end前是tab,不是空格,会自动去掉)
  5. end #这个不属于here document,单独作为一个命令, 运行脚本时提示错误(没有叫end的命令)
复制代码

论坛徽章:
0
7 [报告]
发表于 2009-02-03 08:34 |只看该作者

回复 #6 ynchnluiti 的帖子

原来是这样,现在明白了,以前一直不搞有-跟没-的区别,还有一个-跟两个--是一样的吧?

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
8 [报告]
发表于 2009-02-03 09:24 |只看该作者
原帖由 我是DBA 于 2009-2-3 08:34 发表
原来是这样,现在明白了,以前一直不搞有-跟没-的区别,还有一个-跟两个--是一样的吧?

两个 - 时,好像第二个 - 是delimiter的一部分

论坛徽章:
0
9 [报告]
发表于 2009-02-03 09:48 |只看该作者

回复 #8 ynchnluiti 的帖子

没太理解,能不能举例说明一下?谢谢andy

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
10 [报告]
发表于 2009-02-03 09:59 |只看该作者
原帖由 我是DBA 于 2009-2-3 09:48 发表
没太理解,能不能举例说明一下?谢谢andy

-END作为delimiter

  1. cat <<--END
  2. > abc
  3. >       123
  4. >       END
  5. >       -END
  6. abc
  7. 123
  8. END
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP