Echo output is different from expected formatted output

后端 未结 2 1153
Happy的楠姐
Happy的楠姐 2021-01-24 09:44

I\'m using the following formatting for echo

It should output text that is both bold and underlined, but instead of making it bold it\'s giving a \'brighter\' variant o

相关标签:
2条回答
  • 2021-01-24 10:23

    It seems you are running bash through the old cygwin.bat, so you are using the Windows Console as terminal, and not through the default Mintty that is a more advanced Terminal.

    By default Cygwin setup install the "Cygwin Terminal" entry in the windows menu

    The content of the menu entry is like

    C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -
    

    with path like

    C:\cygwin64\bin
    

    These items can be a also recreated at the last step of cygwin setup running. There are two box entries :

    □ Create icon on Desktop
    □ Add icon to Start Menu

    If you enable them, both will be recreated

    0 讨论(0)
  • 2021-01-24 10:26

    I have this in my profile :

    ## NORMAL
    export NORMAL=$(tput sgr0)
    
    ## FOREGROUND
    export FGBLACK=$(tput setaf 0)
    export FGRED=$(tput setaf 1)
    export FGGREEN=$(tput setaf 2)
    export FGYELLOW=$(tput setaf 3)
    export FGBLUE=$(tput setaf 4)
    export FGMAGENTA=$(tput setaf 5)
    export FGCYAN=$(tput setaf 6)
    export FGWHITE=$(tput setaf 7)
    export FGBRIGHT=$(tput bold)
    export FGNORMAL=$(tput sgr0)
    export FGBOLD=$(tput bold)
    
    ## BACKGROUND
    export BGBLACK=$(tput setab 0)
    export BGRED=$(tput setab 1)
    export BGGREEN=$(tput setab 2)
    export BGYELLOW=$(tput setab 3)
    export BGBLUE=$(tput setab 4)
    export BGMAGENTA=$(tput setab 5)
    export BGCYAN=$(tput setab 6)
    export BGWHITE=$(tput setab 7)
    
    ## SHAPE
    export SHUNDERLINE=$(tput smul)
    export SHBOLD=$(tput bold)
    export SHSBOLD=$(tput smso)
    

    So I can easily use it in the command line or in my scripts. For instance :

    #!/bin/bash
    
    echo "This is ${FGRED}foreground red${NORMAL}"
    echo "This is ${BGRED}background red${NORMAL}"
    echo "This is ${FGYELLOW}${BGRED}background red and foreground yellow${NORMAL}"
    echo "This is ${SHUNDERLINE}underlined${NORMAL}"
    echo "This is ${FGCYAN}${SHUNDERLINE}cyan underlined${NORMAL}"
    echo "This is ${SHBOLD}bold${NORMAL}"
    echo "This is ${SHUNDERLINE}${SHBOLD}underlined bold${NORMAL}"
    echo "This is ${FGBLUE}${SHBOLD}blue bold${NORMAL} and this ${FGBLUE} normal blue${NORMAL}"
    echo "This is ${SHSBOLD}standout bold${NORMAL}"
    

    Which results in outputs like this :

    Hope its useful for you!

    0 讨论(0)
提交回复
热议问题