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",
`;

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 @   xgqfrms  阅读(39)  评论(8编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-12-16 互联网网络用语缩略语查询网站 All In One
2020-12-16 vue 的 computed 属性在什么时间执行
2020-12-16 vue v-on-clickaway
2020-12-16 vuex 3.x All In One
2020-12-16 vue 自动注册全局组件
2019-12-16 script async / defer
2019-12-16 Chrome Dark Theme
点击右上角即可分享
微信分享提示