How to modify the color of the Linux system shell script output text

  

Linux system can modify the color of the shell script output text, so that it can be distinguished from other text, so that users can distinguish the output text. So how to modify the color of the Linux system shell script output text?

Shell Function:

echocolor(){

color=${1} && shift

case ${color} in

black)

echo -e “\\e[0;30m${@}\\e[0m”

;;

red)

echo -e “\\e[0;31m${@}\\e[0m”

;;

green)

echo -e &ldquo ;\\e[0;32m${@}\\e[0m”

;;

yellow)

echo -e “\\e[0;33m$ {@}\\e[0m”

;;

blue)

echo -e “\\e[0;34m${@}\\e[0m”

;;

purple)

echo -e “\\e[0;35m${@}\\e[0m”

;;

cyan)

echo -e “\\e[0;36m${@}\\e[0m”

;;

*)

echo -e “\\e[0;37m${@}\\e[0m”

;;

esac # --- end of case -- -

}

Example of use:

cd $(dirname $( Readlink -f ${0}))

echocolor purple “》 Current directory: ${PWD}”

modname=$(grep ‘obj-m’ Makefile |  Awk ‘{print $3}& rsquo;) && modname=${modname/.o}

echocolor purple “》 Module Name: ${modname}”

Echocolor yellow “"" Uninstall the old module..”

adb shell rmmod ${modname}

echocolor yellow “"" Compiling..”

make

echocolor yellow “》》 Uploading files..”

adb push k860_words_count.ko /tmp/

echocolor yellow “》》 Installing Module..”

adb shell insmod /tmp/k860_words_count.ko

echocolor cyan “》》 Output debugging information..”

adb shell cat /proc /kmsg |  Grep word

Screenshot:

The above is the modification method of the output color of the Linux system shell script, so that the input text and output text can be easily distinguished to avoid unnecessary Confusion.

Copyright © Windows knowledge All Rights Reserved