I have a very simple bash script written for my Kali Linux distro so I don't have to run apt-get update, apt-get upgrade, apt-get dist-upgrade, apt-get autoclean, and apt-get autoremove every time I open my laptop. After reading up on the syntax for a few days I still can't get it correct. I'm trying to add something in the script to format the terminal output where it will show Errors in RED. Any help would be greatly appreciated in adding something to my script which will show errors in RED for apt-get upgrade output. Thank you in advance.Just FYI here is my two line script...apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
Format terminal output to show apt-get upgrade errors in RED
apt;colors
I've written a little script that will color whatever string you give it:#!/usr/bin/env perluse Getopt::Std;use strict;use Term::ANSIColor; my %opts;getopts('hic:l:',\%opts);    if ($opts{h}){      print<<EoF; Use -l to specify the pattern(s) to highlight. To specify more than one pattern use commas. -l : A Perl regular expression to be colored. Multiple expressions can be     passed as comma separated values: -l foo,bar,baz-i : makes the search case sensitive-c : comma separated list of colors;EoF      exit(0);    }my $case_sensitive=$opts{i}||undef;my @color=('bold red','bold blue', 'bold yellow', 'bold green',            'bold magenta', 'bold cyan', 'yellow on_magenta',            'bright_white on_red', 'bright_yellow on_red', 'white on_black');if ($opts{c}) {   @color=split(/,/,$opts{c});}my @patterns;if($opts{l}){     @patterns=split(/,/,$opts{l});}else{    $patterns[0]='\*';}# Setting $| to non-zero forces a flush right away and after # every write or print on the currently selected output channel. $|=1;while (my $line=<>) {     for (my $c=0; $c<=$#patterns; $c++){    if($case_sensitive){        if($line=~/$patterns[$c]/){           $line=~s/($patterns[$c])/color($color[$c]).$1.color(reset)/ge;        }    }    else{        if($line=~/$patterns[$c]/i){          $line=~s/($patterns[$c])/color($color[$c]).$1.color(reset)/ige;        }      }    }    print STDOUT $line;}If you save it as color in a directory that is in your $PATH and make it executable (chmod +x /usr/bin/color), you can color whatever you like:sudo apt-get install nonexistent-package 2>&1 | color -l E:,errorThe 2>&1 is needed to redirect error messages to the standard output. 