如何使用 printf 打印粗体文本?
How to print bold text using printf?
我想使用 printf
打印粗体文本。我该怎么做?
printf '%s\n' "3[1m"bold_text"3[0m"
不起作用。它显示:
3[1mbold_text3[0m
但是,相同的字符串在 echo -e
:
下工作正常
echo -e "3[1m"bold_text"3[0m"
bold_text
正确答案是使用 %b
格式说明符而不是 %s
:
printf '%b\n' "3[1m"bold_text"3[0m"
来自help printf
:
%b - expand backslash escape sequences in the corresponding argument
我想使用 printf
打印粗体文本。我该怎么做?
printf '%s\n' "3[1m"bold_text"3[0m"
不起作用。它显示:
3[1mbold_text3[0m
但是,相同的字符串在 echo -e
:
echo -e "3[1m"bold_text"3[0m"
bold_text
正确答案是使用 %b
格式说明符而不是 %s
:
printf '%b\n' "3[1m"bold_text"3[0m"
来自help printf
:
%b - expand backslash escape sequences in the corresponding argument