I want to test whether a line, read in from a file, has a specific beginning AND an ending containing a word held in a variable. Here's some code:
The input file is:
line one
#; line two
#; line three blah
line four
A minimal script, which fails, is:
declare ENDOFLINE= "blah"
exec 3< "inputfile"
while read LINE <&3
do
if [[ ("$LINE" =~ "^#;") && (( ("$LINE" =~ "${ENDOFLINE%$}") )) ]];
then
echo score!
else echo no score
fi
done
But, if I do:
if [[ ("$LINE" =~ "^#;") && (( ("$LINE" =~ "blah$") )) ]];
it succeeds in identifying the correct line (=> #; line three blah). In other words, I need a compound test condition where the first test is whether the beginning of the line is '#;' and the end of the line is a string contained in the variable $ENDOFLINE .
Thanks for any help.