2013-05-30 17 views
8

Bir sözcüğü yankı cümlelerinin ortasında renklendirmek istiyorum, ancak bunu başaramıyorum.Bash rengi bir sözcük kullanarak echo

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

Ama bu değil:

Bu işleri aptalca yanlış yapıyorum

#!/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." 

?

cevap

5

yellow için ANSI çıkış kodunuza bir m unuttuysanız. Bu çalışır:

yellow='\E[1;33m' 
+0

Teşekkür, hiç !! +1 @nooodl – nsd

+0

Teşekkürler nooodl, şimdi çalışıyor :) – Zippyduda

16

Çok daha iyi, bir ön plan rengini ayarlamak için tput kullanın: o ve o işleri biliyorum

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

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

Ben sadece son zamanlarda görülen, iyi görünüyor tput ile bir bülbül var. Teşekkürler. – Zippyduda

+1

Ayrıca "tput" için [diğer renkler ve komutlar] (http://stackoverflow.com/a/20983251/24874) vardır. Kabuk betikleri için harika bir araç. –