Home > Blockchain >  Bash Script add style to PS3
Bash Script add style to PS3

Time:01-02

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

CodePudding user response:

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}"
  • Related