【问题标题】:colors in dash (not bash)破折号中的颜色(不是 bash)
【发布时间】:2016-09-18 00:18:14
【问题描述】:

在 bash 中,您可以使用(例如)为输出着色

echo -e "\e[34mblue text\e[0m"

但这不适用于破折号。

有没有办法用破折号获得彩色输出?

【问题讨论】:

    标签: bash dash-shell


    【解决方案1】:

    使用 dash、bash、ksh、fish 和 zsh:

    printf '%b' "\033[34;1mblue text\033[0m\n"
    

    【讨论】:

    • 或者您可以使用tput 并完全避免该问题:'echo "$(tput setaf 4)blue text$(tput sgr0)"` 或与printf 等效
    猜你喜欢
    • 2012-03-05
    • 1970-01-01
    • 2012-05-10
    • 2017-01-18
    • 1970-01-01
    • 2015-02-11
    • 2011-11-13
    • 2016-05-30
    相关资源
    最近更新 更多