Linux bash script HereDoc All In One
Linux shell script
multi-lines comments
/ Linux shell scriptblock comments
Linux shell 脚本多行注释
/Linux shell 脚本块注释
HereDoc
EOF
# 这个是单行注释
# EOF 多行注释
<<EOF
Linux Here Documents / Here Doc
这个是多行注释 1
这个是多行注释 2
这个是多行注释 3
EOF
# EOF 多行注释, command
echo <<EOF
Linux Here Documents / Here Doc
这个是多行注释 1
这个是多行注释 2
这个是多行注释 3
EOF
# EOF 多行注释, command
cat <<EOF
Linux Here Documents / Here Doc
这个是多行注释 1
这个是多行注释 2
这个是多行注释 3
EOF
Bash HereDoc Syntax
[COMMAND] <<[-] 'DELIMITER'
Line 1
Line 2
...
DELIMITER
COMMAND
is optional. Works for any command that acceptsredirection
.<<
is theredirection operator
forforwarding
a HereDoc to the COMMAND.-
is a parameter for tab suppression.DELIMITER
in thefirst line
defines a HereDocdelimiter token
. END, EOT, andEOF
are most common, but any multicharacter word that won't appear in the body works.Omit single quotes
on the first line to allow command and variable expansion.- The DELIMITER in the
last line
indicates the end of a HereDoc. Use the same word from the first linewithout
theleading whitespaces
.
The HereDoc itself contains any number of lines with strings, variables, commands, and other inputs.
Bash HereDoc 语法
[命令] <<[-] '分隔符标记'
Line 1
Line 2
...
分隔符标记
命令
是可选的。适用于任何接受重定向
的命令。<<
是用于将 HereDoc 转发到 COMMAND 的重定向运算符
。-
是制表符抑制的参数。第一行
中的 DELIMITER 定义了 HereDoc分隔符标记
。 END、EOT 和EOF
是最常见的,但任何不会出现在正文中的多字符词
都可以使用。在第一行省略单引号
以允许命令
和变量
扩展。最后一行
中的 DELIMITER 表示 HereDoc 的结尾
。使用第一行中没有前导空格
的相同单词。
demos
#!/usr/bin/env bash
echo "auto create templates in current folder..."
echo $0
echo $1
# auto create templates in current folder...
# ./auto-ts-files-generator.sh
# 10
# linux block comments / linux multi-lines comments
<<EOF
Linux Here Documents
这个是多行注释 1
这个是多行注释 2
这个是多行注释 3
EOF
# TODO:
# 1. 接收参数 ✅
# 2. 读取模版
# 3. NPM publish
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
EOF
https://www.cnblogs.com/xgqfrms/tag/EOF/
https://phoenixnap.com/kb/bash-heredoc
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!