答案1
这很简单,你可以试试这个:
# 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