How to print bold text in terminal? [closed]

var=apple
echo " the $var is a fruit "

I want to print the apple is a fruit in bold I tried this

echo $'\e[32;1m the $var is a fruit\e[0m\e ;'

but not working, please help me.


Solution 1:

Variable expansion does not work in single quotes.

So either you can end the quote and start again (but I think this is very unreadable):

echo $'\e[32;1m the '"$var"$' is a fruit\e[0m'

Or simply use echo -e:

echo -e "\e[32;1m the $var is a fruit\e[0m"

Even better option would be to use printf:

printf '\e[32;1m the %s is a fruit\n\e[0m' "$var"