居中对齐/对齐 ASCII 艺术在 bash 中



>我只是在做我的bash项目,

我希望每当终端以任何分辨率执行脚本时,标头 ascii 艺术都会在中心自动调整。有可能的伴侣吗? 以下是我的代码:

#!/bin/bash
clear
echo
echo -e "tt1▄██████▄#0000▄████████0000▄████████11▄██████▄ ";
echo -e "tt███0000███111███0110███111███1011███1███#0000██";
echo -e "tt███0001███111███0111███111███1100█▀11███#ffff██";
echo -e "tt███0010███11▄███▄▄▄▄██▀11▄███▄▄▄11111███#0000██";
echo -e "tt███0011███1▀▀███▀▀▀▀▀111▀▀███▀▀▀11111███#ffff██";
echo -e "tt███0100███1▀███████████111███1101█▄11███#0000██";
echo -e "tt███0101███111███1000███111███1110███1███#ffff██";
echo -e "tt1▀██████▀ffff███1001███111██████████11▀██████▀1";
echo -e "nn"

您可以使用返回终端宽度的 COLUMNS 环境变量。

banner_width=46
indent=$(( (COLUMNS - banner_width) / 2 ))
prefix=''
for ((i=1; i<=indent; i++)) ; do
    prefix+=' '
done
echo
echo -e "${prefix}1▄██████▄#0000▄████████0000▄████████11▄██████▄ ";

最新更新