Linux bash script HereDoc All In One

发布时间 2023-03-24 08:18:34作者: xgqfrms

Linux bash script HereDoc All In One

Linux shell script multi-lines comments / Linux shell script block comments

Linux shell 脚本多行注释/Linux shell 脚本块注释

HereDoc

EOF

# 这个是单行注释
# EOF 多行注释

<<EOF
Linux Here Documents / Here Doc
这个是多行注释 1
这个是多行注释 2
这个是多行注释 3
EOF

image

# 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 accepts redirection.
  • << is the redirection operator for forwarding a HereDoc to the COMMAND.
  • - is a parameter for tab suppression.
  • DELIMITER in the first line defines a HereDoc delimiter token. END, EOT, and EOF 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 line without the leading 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

https://unix.stackexchange.com/questions/425276/using-dev-stdin-and-a-heredoc-to-pass-a-file-from-the-command-line



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!