LINUX SHELL Here Documents

本文介绍了一个Bash脚本技巧——Heredocuments。它允许开发者指定一个字符串作为输入边界,从而将一系列文本作为命令的标准输入。文章通过示例展示了如何使用Heredocuments来简化脚本中数据的传递。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


今天学到一个Linux Bash的新词语,Here docuemnts。



Frequently, your script might call on another program or script that requires input. The here document provides a way of instructing the shell to read input from the current source until a line containing only the search string is found (no trailing blanks). All of the lines read up to that point are then used as the standard input for a command.

简答的说,就是直接将需要的文件内容写到Bash一起。


echo "These are the web browsers on this system:"
 
# Start here document
cat << BROWSERS
mozilla
links
lynx
konqueror
opera
netscape
BROWSERS
# End here document


从上面可以看出,以BROWSERS开始,到BROWSERS结束为一个文档。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值