echo printing -e in bash

后端 未结 2 959
灰色年华
灰色年华 2020-12-19 20:47

I\'ve gotten this script I\'ve created in Bash, and one of the functions I\'m using is echo and I\'m using the -e flag for interpretations of

2条回答
  •  [愿得一人]
    2020-12-19 21:48

    Remove the trailing backslashes and add a closing quote:

    NC='\033[31;0m'       # no colors or formatting
    RED='\033[0;31;1m'    # print text in bold red
    PUR='\033[0;35;1m'    # print text in bold purple
    YEL='\033[0;33;1m'    # print text in bold Yellow
    GRA='\033[0;37;1m'    # print text in bold Gray
    echo -e "This ${YEL}Message${NC} has color\nwith ${RED}new${NC} lines."
    

    And it works as expected in bash.

    If you save this script into a file, run it like bash .


    Try type -a echo to see what it is. The first line of output should be echo is a shell builtin:

    $ type -a echo
    echo is a shell builtin
    echo is /usr/bin/echo
    echo is /bin/echo
    

提交回复
热议问题