Thanks guys, both are working ok, but I tend to use PHV's solution.
As not always $2 has a value, I have coded the following which does not work (grep does not return the matches). Any idea why?
if [ -n "$1" ]; then
tg1="-e \"$1\""
fi;
if [ -n "$2" ]; then
tg2=" -e \"$2\""
fi;
my_string=${tg1}${tg2}
echo $my_string #displays ok as expected eg -e "error" -e "has aborted"
grep ${my_string} $my_file
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.