gpt4 book ai didi

macos - 如何让 osx shell 脚本在 echo 中显示颜色

转载 作者:行者123 更新时间:2023-11-29 08:41:51 25 4
gpt4 key购买 nike

我正在尝试为我在 Mac 上运行的 bash 脚本中的错误添加颜色输出。问题是颜色不起作用。我创建了最简单的脚本来证明它不起作用:

#!/bin/bash

echo -e "\e[1;31m This is red text \e[0m"

但是,当我运行它时,我根本看不到任何颜色,如图所示。然而,ls 命令的颜色输出工作正常。

enter image description here

最佳答案

使用 \033\x1B而不是 \e代表 de <Esc>性格。

echo -e "\033[1;31m This is red text \033[0m"

参见 http://misc.flogisoft.com/bash/tip_colors_and_formatting

关于macos - 如何让 osx shell 脚本在 echo 中显示颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28782394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com