我想使用 printf
打印粗体文本。我该怎么做?
printf '%s\n' "\033[1m"bold_text"\033[0m"
没用。它显示:
\033[1mbold_text\033[0m
但是,相同的字符串在 echo -e
下工作正常:
echo -e "\033[1m"bold_text"\033[0m"
bold_text
最佳答案
正确的答案是使用 %b
格式说明符而不是 %s
:
printf '%b\n' "\033[1m"bold_text"\033[0m"
来自help printf
:
%b - expand backslash escape sequences in the corresponding argument
关于bash - 如何使用 printf 打印粗体文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63610540/