我知道这个标题可能有点让人困惑。然而,我有一个例子,GNU Nano。Nano编辑器的顶部有一条线条,其颜色完全颠倒。

有人知道如何在Bash脚本中实现这一点吗?
发布于 2020-05-31 00:20:36
这很容易,你可以试试这个:
# Reset
reset='\033[0m'
# White Background
BG='\033[47m'
# Black Foreground
FG='\033[0;30m'
# Usage
echo -e "$FG$BG This will print black text on white background $reset"如果你想整条线:
reset='\033[0m'
BG='\033[47m'
FG='\033[0;30m'
text="A black text on white"
cols=$(tput cols)
# Left Aligned
x=$((cols-${#text}))
printf "$FG$BG%s%*s$reset\n" "$text" $x
# Centered text
x_center=$(((${#text}+cols)/2))
x_rest=$((cols-x_center))
printf "$FG$BG%*s%*s$reset\n" $x_center "$text" $x_rest示例输出:

https://unix.stackexchange.com/questions/590044
复制相似问题