console 如何在Bash中輸出粗體文本?
2
Answers
我假設bash運行在一個兼容vt100的終端上,用戶沒有明確關閉對格式化的支持。
首先,使用-e
選項打開對echo
特殊字符的支持。 稍後,使用ansi轉義序列ESC[1m
,如:
echo -e "\033[1mSome Text"
更多關於ansi轉義序列的例子在這裡: ascii-table.com/ansi-escape-sequences-vt-100.php
bash console formatting echo
我正在寫一個Bash腳本,在屏幕上打印一些文本:
echo "Some Text"
我可以格式化文本嗎? 我想使它大膽。
165 votes
bash
理論上是這樣的:
# BOLD
$ echo -e "\033[1mThis is a BOLD line\033[0m"
This is a BOLD line
# Using tput
tput bold
echo "This" #BOLD
tput sgr0 #Reset text attributes to normal without clear.
echo "This" #NORMAL
# UNDERLINE
$ echo -e "\033[4mThis is a underlined line.\033[0m"
This is a underlined line.
但實際上,它可能會被解釋為“高強度”顏色。
(來源: http://unstableme.blogspot.com/2008/01/ansi-escape-sequences-for-writing-text.html : http://unstableme.blogspot.com/2008/01/ansi-escape-sequences-for-writing-text.html )
bash1
163