• Uncategorized

About linux : Bash-Script-add-style-to-PS3-closed

Question Detail

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?

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

Question Answer

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

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.