[ "${filename:$length:1}" == "*" ] && echo yes
There was no space in your message between "*"and ]. This confuses bash. If the statement begins with [, bash insists that its last argument be ]. Without a space, the last argument "*"]that after removing the quote becomes *]which is not ].
Putting it all together:
length=${
((length--))
[ "${filename:$length:1}" == "*" ] && echo yes
: :
[ "${filename: -1}" == "*" ] && echo yes
-1 . :
[[ $filename = *\* ]] && echo yes
bash [[. , $filename glob *\*, " ", \* . , , *. [[ @broslow.