while running below command in terminal it's working fine with highlighted red and white colour matching with the pattern as per image below,
$ grep -Ff file1.txt file2.txt
But when I put the same command in script as pl.sh
file and run it it's not highlighting at all as above image. I am not sure what I am doing wrong! Do I need to change the script?
#!/bin/bash
# Main file:
echo -n "Choose the Main Assignment File : "
read mainfile
# Compare a file
echo -n "Choose a file to compare with : "
read comparefile
# Compare two files and highlight differences
sudo grep -Ff "$mainfile" "$comparefile"
grep
to use color ex.alias grep='grep --color=auto'
sudo
. Why?pl.sh
file or somewhere elsesudo
. So you'd need to add the color option to grep explicitly ex.grep --color=always -Ff "$mainfile" "$comparefile"