Here-Document

10 篇文章 0 订阅
Here-document

The redirection operators << and <<- both allow redirection of lines contained in a shell input file, known as a here-document, to the standard input of a command.

The here-document is treated as a single word that begins after the next newline character and continues until there is a line containing only the delimiter, with no trailing blank characters. Then the next here-document starts, if there is one. The format is as follows:


[n]<<word
    here-document
delimiter

If any character in word is quoted, the delimiter is formed by performing quote removal on word, and the here-document lines will not be expanded. Otherwise, the delimiter is the word itself.

If no characters in word are quoted, all lines of the here-document will be expanded for parameter expansion, command substitution and arithmetic expansion. In this case, the backslash in the input will behave as the backslash inside double-quotes (see Double-quotes ). However, the double-quote character (") will not be treated specially within a here-document, except when the double-quote appears within $( ), ` ` or ${ }.

If the redirection symbol is <<-, all leading tab characters will be stripped from input lines and the line containing the trailing delimiter. If more than one << or <<- operator is specified on a line, the here-document associated with the first operator will be supplied first by the application and will be read first by the shell. For example:


cat <<eof1; cat <<eof2
Hi,
eof1
Helene.
eof2

The case of a missing delimiter at the end of a here-document is not specified. This is considered an error in the script (one that sometimes can be difficult to diagnose), although some systems have treated end-of-file as an implicit delimiter.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值