【发布时间】:2016-09-18 00:18:14
【问题描述】:
在 bash 中,您可以使用(例如)为输出着色
echo -e "\e[34mblue text\e[0m"
但这不适用于破折号。
有没有办法用破折号获得彩色输出?
【问题讨论】:
标签: bash dash-shell
在 bash 中,您可以使用(例如)为输出着色
echo -e "\e[34mblue text\e[0m"
但这不适用于破折号。
有没有办法用破折号获得彩色输出?
【问题讨论】:
标签: bash dash-shell
使用 dash、bash、ksh、fish 和 zsh:
printf '%b' "\033[34;1mblue text\033[0m\n"
【讨论】:
tput 并完全避免该问题:'echo "$(tput setaf 4)blue text$(tput sgr0)"` 或与printf 等效