gpt4 book ai didi

Bash 使用 echo 给一个单词上色

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

我想在 echo 句子中间给一个词着色,但似乎无法实现。

这个有效:

#!/bin/bash
wipe="\033[1m\033[0m"
yellow='\E[1;33'
echo -e "$yellow"
echo Hello World
echo -e "$wipe"

但这不是:

#!/bin/bash
wipe="\033[1m\033[0m"
yellow='\E[1;33'
black="40m"
echo -e "Output a $yellow coloured $wipe word."
# or
echo -e "Output a ${yellow} coloured ${wipe} word."

我愚蠢地做错了什么? :)

最佳答案

好多了,使用tput设置前景色:

textreset=$(tput sgr0) # reset the foreground colour
red=$(tput setaf 1)
yellow=$(tput setaf 2)

echo "Output a ${yellow} coloured ${textreset} ${red} word ${textreset}."

关于Bash 使用 echo 给一个单词上色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16845699/

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