K
K
kik_krsk2016-06-07 12:28:50
bash
kik_krsk, 2016-06-07 12:28:50

Highlight certain words in bash?

How can I colorize certain words in bash output. For example, when telnetting to cisco connected devices are green, and not connected are red?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2016-06-07
@fox_12

f5d0a03663b24e38a77cf361c10ff170.png

K
krypt3r, 2016-06-07
@krypt3r

More or less like this

#!/usr/bin/env bash

SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"

${SETCOLOR_SUCCESS}
echo "Connected"
${SETCOLOR_NORMAL}

${SETCOLOR_FAILURE}
echo "Not connected"
${SETCOLOR_NORMAL}

${SETCOLOR_WARNING}
echo "Some warning"
${SETCOLOR_NORMAL}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question