I'am trying few days to change color output from command in bash script. I tried some workflows with e.g. trap but without success.The only what partially working is this code:
#!/bin/bash
GRN='\e[32m'
CYN='\e[36m'
END='\e[0m'
echo -e "${GRN}Formating Root partition ..${END}"
echo -e "${CYN}"
(set -x ; mkfs.ext4 -L Root -m 5 /dev/sda2) | GREP_COLOR='49;38;5;007' grep --color=always '.*'
echo -e "${END}"
echo -e "${GRN}Formating Home partition ..${END}"
...
Is there some better way how to do it. Thank you.
What I want is this:
Formating Root partition .. <= Green
mkfs.ext4 -L Root -m 5 /dev/sda2 <= Cyan
mke2fs 1.45.2 (27-May-2019) <= Grey
Creating filesystem with 9175040 4k blocks and 2293760 inodes <= Grey
Filesystem UUID: ... <= Grey
... <= Grey
Formating Home partition .. <= Green