I am new to bash and Linux and not sure why the last character of my selected line isn't appearing empty when it isn't empty. In my code, I am testing if the last character of my second last line == " " if so I would like to echo "yes" otherwise echo "no".
here is my code
Line=$(tail -n-2 file | head -n1)
echo "$Line"
echo "${Line: -1}"
if [ "${Line: -1}" == " " ]; then
echo "yes";
else
echo "no";
fi
the file consistes of:
xxxxxxxxxxxx
xx x x xxx x
xxx xx xxx x
x x xxx xx .
xxxxxxxxxxxx
the output for this is:
x x xxx xx .
yes
I am not sure why when I do echo "${Line: -1}" the output is empty but the output is as expected when I am doing echo "$Line"
any suggestions how I can fix this, thanks
sed -n l(that's lower caseL) to see if there's some invisible characters after that dot such as space, tab or carriage return (if the file comes from Microsoft land)\nand the.was the second last character