xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Linux bash write long string with multi-lines comments All In One

Linux bash write long string with multi-lines comments All In One

linux shell block comments / linux shell multi lines comments

https://stackoverflow.com/a/76127090/5934465

Here documents & Here strings

https://bash.cyberciti.biz/guide/Here_documents

https://bash.cyberciti.biz/guide/Here_strings

demos

string variable

MARKDOWN='
{
    "msgtype": "markdown",
    "markdown": {
        "content": "⏰ '$SH_DATE'\n\n🎉<font color=\"warning\">读书会快捷链接</font>\n\n📘[<font color=\"info\">阅读打卡链接</font>](https://library.xgqfrms.xyz/#/club/share)\n\n👨🏻‍💻[<font color=\"info\">我的链接</font>](https://library.xgqfrms.xyz/#/my)\n\n💰[<font color=\"info\">积分链接</font>](https://library.xgqfrms.xyz/#/mall)\n\n<font color=\"warning\">读书会机器人🤖️ features:</font>\n\n<font color=\"comment\">1. 大大简化进入打卡的流程,跳过 3s 首页的推荐;</font>\n\n<font color=\"comment\">2. 每天早晚两次打卡提醒(08:00 和 20:00) ⏰,降低忘记打卡的风险;</font>\n\n",
        "mentioned_list":["Eric"],
    }
}'


Here Documents

Here Doc

EOF and END are often chosen as the MyUniqueLimitString but any string can be used as long as it does not appear within the here document text.

EOFEND 通常被选为 MyUniqueLimitString,但可以使用任何字符串,只要它没有出现在此处文档文本中即可。

image

#!/bin/bash
cat <<End-of-text
--------------------------
The quick brown fox
jumped over the lazy dog
--------------------------
End-of-text
#!/bin/bash
ACTION="Quickly"

cat <<End-of-txt
The quick brown fox $ACTION
jumped over the lazy dog
End-of-txt


#!/bin/bash
DB_NAME="db064"
PASSWORD="Pa$$w0rd"
APP_USER="user64"
APP_PASSWORD="cfE7JcEbgzW1XUUaEQ"

mysql -u root --password="${PASSWORD}" <<EOF
CREATE DATABASE ${DB_NAME};
CREATE USER '${APP_USER}'@'localhost' IDENTIFIED BY '${APP_PASSWORD}';
GRANT ALL ON ${DB_NAME}.* TO '${APP_USER}'@'localhost'
EOF

https://ss64.com/bash/syntax-here.html

https://en.wikipedia.org/wiki/Here_document

https://tldp.org/LDP/abs/html/here-docs.html

https://linuxhint.com/bash-heredoc-tutorial/

solutions

# EOF

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


# END

<<END
Linux Here Documents
这个多行注释 1
这个多行注释 2
这个多行注释 3
END


# EOL


<<EOL
Linux Here Documents
这个多行注释 1
这个多行注释 2
这个多行注释 3
EOL


# EOM

<<EOM
Linux Here Documents
这个多行注释 1
这个多行注释 2
这个多行注释 3
EOM

js template string

const markdown = `
⏰ '$SH_DATE'\n\n
🎉<font color=\"warning\">读书会快捷链接</font>\n\n
📘[<font color=\"info\">阅读打卡链接</font>](https://library.xgqfrms.xyz/#/club/share)\n\n
👨🏻‍💻[<font color=\"info\">我的链接</font>](https://library.xgqfrms.xyz/#/my)\n\n
💰[<font color=\"info\">积分链接</font>](https://library.xgqfrms.xyz/#/mall)\n\n
<font color=\"warning\">读书会机器人🤖️ features:</font>\n\n
<font color=\"comment\">1. 大大简化进入打卡的流程,跳过 3s 首页的推荐;</font>\n\n
<font color=\"comment\">2. 每天早晚两次打卡提醒(08:00 和 20:00) ⏰,降低忘记打卡的风险;</font>\n\n",
`;

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

Linux bash script HereDoc All In One

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

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

https://www.cnblogs.com/xgqfrms/p/17250153.html

refs

https://stackoverflow.com/questions/7316107/how-to-split-strings-over-multiple-lines-in-bash

https://unix.stackexchange.com/questions/503572/how-to-break-a-long-string-into-multiple-lines-assigned-to-a-variable-in-linux-b

https://serverfault.com/questions/72476/clean-way-to-write-complex-multi-line-string-to-a-variable

https://www.geeksforgeeks.org/multi-line-comment-in-shell-script/

https://unix.stackexchange.com/questions/157328/how-can-i-remove-all-comments-from-a-file



©xgqfrms 2012-2021

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

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


posted @ 2021-12-16 12:47  xgqfrms  阅读(39)  评论(8编辑  收藏  举报