Score:-1

How to print bold text in terminal?

tr flag
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.

24601 avatar
in flag
how does this relate to ubuntu?
pLumo avatar
in flag
Please improve your question: "*i need to print this*" is not a good title, and "*not working*" not a good error description. Also, you want to print bold, but your example is printing green+bold.
Score:1
in flag

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"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.