Change text color from echo command?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Change text color from echo command?
# 1  
Old 05-06-2018
Change text color from echo command?

I have a bash script that starts and stops a game among other things through in.fifo and out.fifo

In game the text comes out gray . Kinda hard to see in game window .

I would like to change it to purple and maybe capitalize it.

Code:
#!/bin/bash
#nwservctl.sh
cd /home/nwn/.local/share/"Neverwinter Nights"/bin/linux-x86
#control command for nwn server, requires empty-expect

# **** BASIC CONFIGURATION ****


purple="\033[1;35m"

# Num of log directory to keep
LOG_HIST_NUM=9

# Seconds to wait for server loading
SECONDS_TO_WAIT=100

#Default Countdown in seconds
COUNTDOWN=60

# nwserver command: nwserver or nwnstartup.sh for NWNX2
#NWSERVER_COMMAND="nwnstartup.sh" #NWNX2
NWSERVER_COMMAND="nwserver-linux -module SnowBlizzard_CEP" #Basic nwserver
FIRST_EXIT_PHRASE="Restarting server in"
SECOND_EXIT_PHRASE="seconds please logout..."

# output passfrase to wait for module loaded
#PASS_PHRASE="0x08203e79" # NWNX2 init if you use nwnstartup.sh
PASS_PHRASE="Running..." # Basic nwserver

# **** END BASIC CONFIGURATION ****

# **** ADVANCED CONFIGURATION ******
# ONLY FOR EXPERTS

# start server command
NWSERVER_START="empty -f -i ./in.fifo -o ./out.fifo ./$NWSERVER_COMMAND"

# wait for loaded command
WAIT_LOADED="empty -w -t $SECONDS_TO_WAIT -i ./out.fifo -o ./in.fifo $PASS_PHRASE" # FOR nwnstartup.sh

# return output from server command
# use a timeout until all commands are debugged
CATCH_OUTPUT="empty -r -t 30 -b 8192 -i ./out.fifo"

# first line argument
ARG1="$1"

# exit code
EXCODE=0

# *** CODE ***

#check if arguments exist
if [ "x$ARG1" = "x" ] || [ "x$ARG1" = "xusage" ] || [ "x$ARG1" = "x--help" ]; then
echo "$Usage: `basename $0` start | restart [countdown [n]]" >&2
echo " `basename $0` stop [countdown [n]] | kill | status [purple]" >&2
echo " `basename $0` info [pid | pcpu | etime | pmem | vsz ] | --help" >&2
echo " `basename $0` <nwsever commands> if server is running" >&2
exit 1
fi

#nux check if nwserver is running exit if command is not
if [ "$(pidof nwserver-linux)" ] ; then
if [ "x$ARG1" = "xstart" ] ; then
echo "`basename $0` - nwserver already running..."
exit 1
else
: # do nothing continue
fi
else
if [ "x$ARG1" = "xstart" ] ; then
: # do nothing continue
else
echo "`basename $0` - nwserver is not running..."
exit 1
fi
fi

case $ARG1 in
start)
# rotate logs
[ -d ./logs ] || mkdir -p ./logs
if [ -d "./logs/logs.$LOG_HIST_NUM" ]; then
rm -f -r "./logs/logs.$LOG_HIST_NUM"
fi
for ((ddest=$LOG_HIST_NUM; ddest >= 2 ; ddest--)); do
let "dsourc = $ddest - 1"
if [ -d "./logs/logs.$dsourc" ]; then
mv -f "./logs/logs.$dsourc" "./logs/logs.$ddest"
fi
done

#move log.0 in log.1
mv -f ./logs.0 ./logs/logs.1
mkdir ./logs.0
#end rotate logs

shift
NWSERVER_START="$NWSERVER_START $*"
$NWSERVER_START
echo "Starting nwserver please wait.."
sleep 5
$WAIT_LOADED

if [ "$(pidof nwserver-linux)" ]
then
echo "nwserver is running now"
else
echo "nwserver loading failed.."
EXCODE=1
fi
;;
stop|restart)
if [ "x$2" = "xcountdown" ]; then
if [ "$3" -gt 0 ]; then
COUNTDOWN="$3"
fi
while [ "$COUNTDOWN" -gt 0 ]; do
$0 "say $FIRST_EXIT_PHRASE $COUNTDOWN $SECOND_EXIT_PHRASE"
let "COUNTDOWN -= 10"
sleep 10
done
fi
echo "exit" | empty -s -o ./in.fifo
$CATCH_OUTPUT
if [ "x$1" = "xrestart" ]; then
echo "restarting in 10 seconds please wait..."
sleep 10
$0 "start"
fi
;;
info)
case "$2" in
pcpu|etime|pmem|vsz)
ps -p "$(pidof nwserver-linux)" -o "$2="
;;
pid)
echo "$(pidof nwserver-linux)"
;;
*)
ps -p "$(pidof nwserver-linux)" -o pid,comm,etime,pmem,vsz,pcpu
;;
esac
;;
kill)
empty -k "$(pidof nwserver-linux)"
;;
# with return output
status|help|listbans)
echo "$ARG1" | empty -s -o ./in.fifo
$CATCH_OUTPUT
;;
# no return output
playerpassword|dmpassword|adminpassword|oneparty|ilr|elc|difficulty|servername|autosaveinterval|pauseandplay|minlevel|maxlevel|maxclients|export|kick)
echo "$*" | empty -s -o ./in.fifo
#no output to catch
;;
#all other commands default send to nwserver
*)
echo "$*" | empty -s -o ./in.fifo
$CATCH_OUTPUT
;;
esac

exit $EXCODE

Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) when displaying full-line and multi-line sample input, output, and code.

Last edited by Don Cragun; 05-06-2018 at 08:36 PM.. Reason: Get rid of nested ICODE tags; change ICODE tags to CODE tags.
# 2  
Old 05-06-2018
Does the following help?
Code:
purple='\e[1;35m'
black='\e[1;0m'
printf "Default${purple}purple${black}black\n"

which produces the output:
Code:
Defaultpurpleblack

on terminals that accept those types of ANSI terminal escape sequences.
# 3  
Old 05-07-2018
For the desired capitalisation, with your (presumedly recent) bash shell you could use "Parameter Expansion / Case Modification":
Code:
ARG1=default
printf "%s\n" ${ARG1^^}
DEFAULT

# 4  
Old 05-07-2018
Thanks guys. I will experiment with it this week between server resetsSmilie
# 5  
Old 05-07-2018
FWIW - I think you linux probably has GNU awk (may be called gawk) which supports
Code:
printf("%s\n",toupper( $0))

# 6  
Old 05-07-2018
I'm running Debian 6.

Empty-expect package to handle the in.fifo and out.fifo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change text color in Korn shell to highlight Error

Hi this is my first post, so forgive me if what I'm requesting doesn't make sense. I'm connecting into a Unix server via SSH and using a Korn Shell (#!/bin/ksh). The Unix server has Oracle 11g installed on it and there are a number of scripts already setup to query the Oracle database to perform... (2 Replies)
Discussion started by: KeithJ
2 Replies

2. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies

3. UNIX for Dummies Questions & Answers

How to change color when doing echo in tcsh?

Is it possible to change the color when doing an echo? Example, having the following command print in dark blue. echo "Hello" ---------- Post updated at 11:50 AM ---------- Previous update was at 10:25 AM ---------- Just figured out how to do it (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

change text color in postscript file

Hi everyone, I have a program that produces postscript files on the fly The color of the files produced are in black and white I want to change the text color of postscript file as the file is being produced without having to manually go into the ps file and change it myself. Any Ideas?... (5 Replies)
Discussion started by: walforum
5 Replies

5. Shell Programming and Scripting

Color on echo output does not work

Hi, When I run: echo "\033I see hi in color, but if I run this color is not shown, why? (echo "\033Thanks Israel. ---------- Post updated at 05:17 AM ---------- Previous update was at 04:43 AM ---------- DONE!! I had to run more -v. Thanks (4 Replies)
Discussion started by: iga3725
4 Replies

6. Shell Programming and Scripting

give some color to a word on echo output

Hi Supposed this text output: How can I show $HOSTNAME in other color than blank? :-) KSH on AIX (4 Replies)
Discussion started by: iga3725
4 Replies

7. Shell Programming and Scripting

.bashrc/PS1 command color different color to command output

I have been configuring my .bashrc PS1 to be displayed with some nice colors and in a format that I like, however there is one thing that I cannot figure out (or know if it's even possible). my PS1 line is as follows: export PS1='\\u\@\\h\:\\w\n\\$ \'This makes the command and command output... (0 Replies)
Discussion started by: jelloir
0 Replies

8. Shell Programming and Scripting

Problem using echo command for text starting with /

Hi, i need to print following text using echo: /abc dir/c\ so i tried echo "/abc dir/c\ But it gives me error of Incorrect usage, i am using Hamilton cshell in windows Vista. Can any one please help me. Thanks in advance Sarbjit (3 Replies)
Discussion started by: sarbjit
3 Replies

9. Shell Programming and Scripting

ksh - how to echo something in color and bold

Hi all, I was to echo Hi in Red and Bold ; and echo There is in Green and bold I got bold to working using tput bold but i am having hard time getting the color. Any help is appreciated, jak (4 Replies)
Discussion started by: jakSun8
4 Replies

10. UNIX for Dummies Questions & Answers

How to change the font or color of text

Hi Gurus, I have a small requirement where i want to change the color & font of some text in a file. i have a file error.txt which will be created in the script using egrep. After that iam adding these lines at head & tail to that file using the following code awk 'BEGIN{print"Please... (4 Replies)
Discussion started by: pssandeep
4 Replies
Login or Register to Ask a Question