linux shell脚本eof,Linux shell脚本里面的EOF

I saw this script and I'm not sure why or how it works:

cat >> test << STOP

line 1

line 2

line 3

STOP

or equally

cat >> test << EOF

line 1

line 2

line 3

EOF

That is known as a "Here Tag". Basically it tells the shell that

you are going to enter a multi-line string until "Here". You could

call it anything you want, not just EOF or STOP.

Code:

[mb@ironmaiden mb]$ cat > test

<

> Hello

> world

> HERE

The <

multi-lines until the HERE tag. Thus the shell waits until it sees

HERE to consider the rest of the stuff above it as input for

cat.

Some rules about the Here tags:

1. The tag can be any string, uppercase or lowercase, though most

people use uppercase by convention.

2. The tag will not be considered as a Here tag if there are other

words in that line. In this case, it will merely be considered part

of the string. The tag should be by itself on a separate line, to

be considered a tag.

3. The tag should have no leading or trailing spaces in that line

to be considered a tag. Otherwise it will be considered as part of

the string.

Here's another chunk to consider:

Code:

[mb@ironmaiden mb]$ cat >> test

<

> Hello world HERE

string

> This is a test

> HERE

string

> and a new line

> HERE

Note that in the above, we have the word HERE showing up 3 times.

The first two times, it occurs with other words or leading spaces

and hence it is considered as part of the string.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值