I want to print bold text using printf
. How do I do it?
printf '%s\n' "\033[1m"bold_text"\033[0m"
doesn't work. It displays:
\033[1mbold_text\033[0m
However, the same string works fine with echo -e
:
echo -e "\033[1m"bold_text"\033[0m"
bold_text
The right answer is to use the %b
format specifier instead of %s
:
printf '%b\n' "\033[1m"bold_text"\033[0m"
From help printf
:
%b - expand backslash escape sequences in the corresponding argument