我想给bash的提示着色,并尝试通过函数来实现。与我预期的不同,颜色值显示为普通文本。有什么问题吗?
user@host:directory$ cat ~/.bashrc
get_color() {
local color="$1"
case "${color}" in
"BLUE") echo "\[\e[1;34m\]";;
"RED") echo "\[\e[1;31m\]";;
"GREEN") echo "\[\e[1;32m\]";;
"GRAY") echo "\[\e[1;37m\]";;
"WHITE") echo "\[\e[00m\]";;
*) echo "\[\e[00m\]";;
esac
}
PS1="\u@\h:\W\$(get_color RED)\$ "
user@host:directory$ source ~/.bashrc
user@host:directory\[\e[1;31m\]$