简体   繁体   中英

Bash Script add style to PS3

I would like to know how to apply styles to the PS3 variable in bash. I have tried various ways of applying style and I cannot apply it.

For example, how could you add red text on PS3 using the RED variable.

Thanks in advance and apologies for the silly question.

Code:

#! /usr/bin/bash

BGMAGENTA="\e[45m"
YELLOW="\e[33m"
RED="\e[1;31m"
GREEN="\e[1;32m"
ENDCOLOR="\e[0m"

UNDERLINE="\e[4m"


echo -e "\n${BGMAGENTA}BabyMalware esta en desarollo${ENDCOLOR}\n"

PS3=$'\n'"babyMalware > "
options=("Malware LAN" "Malware WAN" "Salir")

select opt in "${options[@]}"
do
    case $opt in
        "Malware LAN")
            echo -ne "\nIP Privada : "
            hostname -I
            echo -e "\n"
            ;;

        "Malware WAN")
            echo -ne "IP Publica WAN : "
            publicip | tail -n 1
            ;;

        "Salir")
            echo "Saliendo..."
            break
            ;;

        *) echo "Opción elegida no valida : $REPLY";;
        esac
done

Instead of relying on internal backslash expansion, store the escape character directly instead:

BGMAGENTA=$'\e[45m'
YELLOW=$'\e[33m'
RED=$'\e[1;31m'
GREEN=$'\e[1;32m'
ENDCOLOR=$'\e[0m'
UNDERLINE=$'\e[4m'

Also you need to specify the special readline characters. These are equivalent to \[ and \] in PS1 .

RL_BEGIN=$'\001'
RL_END=$'\002'
PS3=$'\n'"${RL_BEGIN}${RED}${RL_END}babyMalware > ${RL_BEGIN}${ENDCOLOR}${RL_END}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM