0

This is the script. Does anyone know how I can change the color of the text so when I open it in terminal it changes the color?

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

I tried it but this is what came up in 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' 

enter image description here

this is what shows up and i don't know why hahaha

8
  • You mean like have the color always that color after you set it, or like a one time thing?
    – Nick
    Jul 6, 2013 at 15:48
  • Yea so when i make that script executable and run it in Terminal i want the text to change to a color i want but it will only change color when i run that script
    – Jester
    Jul 6, 2013 at 15:50
  • So just basically just a one time thing, i only want it to change color when i open the script
    – Jester
    Jul 6, 2013 at 15:54
  • I just want to add a color to that script so when i open it the "put what ever you want here" will be a different color in terminal
    – Jester
    Jul 6, 2013 at 15:59
  • I don't know about that, if you can do it I mean, I surfed around on google abit, and came up with nothing.
    – Nick
    Jul 6, 2013 at 16:15

1 Answer 1

0

May be this is what You want:

#!/bin/bash

PROGNAME=${0##*/}

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

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

Edit:

Minimal working example with expect:

#!/usr/bin/expect -f 

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

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

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

Edit 2:

Oh, I solved it:

#!/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

makes all text blue.

4
  • Can you add the color black to the script and paste it please? I don't know how to add the color, can you complete the script? THanks :D
    – Jester
    Jul 6, 2013 at 19:15
  • Can you add the color black to this script please
    – Jester
    Jul 6, 2013 at 20:30
  • 1
    @Jester: it looks like what I've posted is not what You need: I posted bash, while You need to do expect. I don't know expect unfortunately.
    – Adobe
    Jul 6, 2013 at 20:48
  • Yeah it was expect, and it's alright man, thanks for trying to help though! :D
    – Jester
    Jul 6, 2013 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .