How does one output bold text in Bash?

后端 未结 5 1854
南笙
南笙 2020-12-02 03:55

I\'m writing a Bash script that prints some text to the screen:

echo \"Some Text\"

Can I format the text? I would like to make it bold.

5条回答
  •  没有蜡笔的小新
    2020-12-02 04:09

    In theory like so:

    # 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. 
    

    But in practice it may be interpreted as "high intensity" color instead.

    (source: http://unstableme.blogspot.com/2008/01/ansi-escape-sequences-for-writing-text.html)

提交回复
热议问题