Como adiciono uma cor personalizada a este script?

0

Este é o script. Alguém sabe como eu posso mudar a cor do texto então quando eu abri-lo no terminal ele muda de cor?

#!/usr/bin/expect -f
spawn -noecho bash
expect "$ " 
send "put what ever you want here"
interact
exit

Eu tentei, mas é isso que surgiu no Terminal

'PROMPT_BLUE='tput setf 1'
PS1='[$PROMPT_BLUE]'
john@john:~$ PROMPT_BLUE='tput setf 1'
john@john:~$ PS1='[$PROMPT_BLUE]'
[]perl put what ever you want here' 

isto é o que aparece e eu não sei porque hahaha

    
por Jester 06.07.2013 / 15:47

1 resposta

0

Pode ser isso que você deseja:

#!/bin/bash

PROGNAME=${0##*/}

# colors:
BLUE='3[94m'
GREEN="\e[0;32m"
RED='3[91m'
BLACK='3[0m'

# program:
echo -e "${RED}${PROGNAME}: ${GREEN}Done.${BLACK}"

Editar :

Exemplo de trabalho mínimo com expect :

#!/usr/bin/expect -f 

# colors:
# BLUE='3[94m'
# GREEN="\e[0;32m"
# RED='3[91m'
# BLACK='3[0m'

# we need byte code. Let's get one for the blue:
# python -c "print ''.join([r'\x%x' % ord(c) for c in \"3[94m\"])"
# gives: \x1b\x5b\x39\x34\x6d
set blue "\x1b\x5b\x39\x34\x6d"

# program:
send "${blue}hello world\n"

Editar 2 :

Ah, resolvi:

#!/usr/bin/expect -f 

spawn -noecho bash
send "PROMPT_BLUE='tput setf 1'\nPS1='\[\$PROMPT_BLUE\]'\n"
expect "$ " 
send "put what ever you want here"
interact
exit

torna todo o texto azul.

    
por Adobe 06.07.2013 / 17:48