我想在一个回声句中间对一个词进行着色,但似乎无法实现这一点.
这有效:
#!/bin/bash
wipe="\033[1m\033[0m"
yellow='\E[1;33'
echo -e "$yellow"
echo Hello World
echo -e "$wipe"
Run Code Online (Sandbox Code Playgroud)
但这不是:
#!/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."
Run Code Online (Sandbox Code Playgroud)
我愚蠢的做错了什么?:)
tar*_*lah 17
更好的是,使用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}."
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8867 次 |
最近记录: |