![如何从 Bash 脚本打印现有的 ASCII 艺术?](https://linux22.com/image/985021/%E5%A6%82%E4%BD%95%E4%BB%8E%20Bash%20%E8%84%9A%E6%9C%AC%E6%89%93%E5%8D%B0%E7%8E%B0%E6%9C%89%E7%9A%84%20ASCII%20%E8%89%BA%E6%9C%AF%EF%BC%9F.png)
我刚刚看到了下面的 ASCII 艺术。
0000_____________0000________0000000000000000__000000000000000000+
00000000_________00000000______000000000000000__0000000000000000000+
000____000_______000____000_____000_______0000__00______0+
000______000_____000______000_____________0000___00______0+
0000______0000___0000______0000___________0000_____0_____0+
0000______0000___0000______0000__________0000___________0+
0000______0000___0000______0000_________000___0000000000+
0000______0000___0000______0000________0000+
000______000_____000______000________0000+
000____000_______000____000_______00000+
00000000_________00000000_______0000000+
0000_____________0000________000000007
我有一个 bash 脚本,我想打印这个。我该怎么做?
为了使事情保持简单,我可能想要重新分配这个,我更希望答案不需要安装额外的东西。
答案1
这是我能生成的最短形式,可以准确打印该007
字符串:
base64 -d <<<"H4sIAJM2MVYAA1NQgAEDIIhHBsgCBmgAU8TAQJsL2SgU41AFiDALYRhUF8I0NAEUCbBZUB7MBGRrUXX
g8DC6CagORwkYtDCDcw3IMwDdOBL1IyRRwpBI7cihTlSYkRRNUHcRnUZgXIQGIlOoOQC/4ufk0gIAAA==" | gunzip
答案2
那么echo
?:
echo -e " 0000_____________0000________0000000000000000__000000000000000000+\n 00000000_________00000000______000000000000000__0000000000000000000+\n 000____000_______000____000_____000_______0000__00______0+\n 000______000_____000______000_____________0000___00______0+\n 0000______0000___0000______0000___________0000_____0_____0+\n 0000______0000___0000______0000__________0000___________0+\n 0000______0000___0000______0000_________000___0000000000+\n 0000______0000___0000______0000________0000+\n 000______000_____000______000________0000+\n 000____000_______000____000_______00000+\n 00000000_________00000000_______0000000+\n 0000_____________0000________000000007;"
每个换行符都已替换为,\n
以便将其全部放在一行中
它不会调整到终端的大小(除非你检查终端的宽度和echo
正确的尺寸),而且它也不是那么短(有没有更好的方法重复字符?)但它应该可以工作。如果你还想要颜色,你可以使用转义码:
echo -e "\033[31m 0000\033[0m_____________0000________0000000000000000__000000000000000000+\n\033[31m 00000000\033[0m_________00000000______000000000000000__0000000000000000000+\n\033[31m 000\033[0m____000_______000____000_____000_______0000__00______0+\n\033[31m 000\033[0m______000_____000______000_____________0000___00______0+\n\033[31m 0000\033[0m______0000___0000______0000___________0000_____0_____0+\n\033[31m 0000\033[0m______0000___0000______0000__________0000___________0+\n\033[31m 0000\033[0m______0000___0000______0000_________000___0000000000+\n\033[31m 0000\033[0m______0000___0000______0000________0000+\n\033[31m 000\033[0m______000_____000______000________0000+\n\033[31m 000\033[0m____000_______000____000_______00000+\n\033[31m 00000000\033[0m_________00000000_______0000000+\n\033[31m 0000\033[0m_____________0000________000000007;"
顺便说一句,你可能要考虑版权和其他无聊的东西,这取决于你如何使用它 - 例如此版本类似的东西似乎仍然受版权保护。
答案3
将字符放入文件中即可cat
。
cat 007.txt
使用“此处文档”
cat <<EOF
0000_____________0000________0000000000000000__000000000000000000+
00000000_________00000000______000000000000000__0000000000000000000+
. . .
EOF
echo
包含嵌入换行符的字符串
echo ' 0000_____________0000________0000000000000000__000000000000000000+
00000000_________00000000______000000000000000__0000000000000000000+
. . .'
这些方法的优点是艺术仍然具有可读性。
答案4
安装banner
包并创建 bash 脚本
sudo apt-get install sysvbanner
检查下面的命令示例
banner 007