The problem is this assignment
arrchar=( $(fold -w1 "$myfile" | sort -u) )
where you rely on word splitting to populate the array per character, unfortunately it also expands *
so if your file in question contains an asterisk the array will list the files in your current directory instead of a literal *
.
You can e.g. temporarily disable globbing to avoid this, for example
set -o noglob
arrchar=( $(fold -w1 "$myfile" | sort -u) )
set +o noglob
or use read
to directly read into the array via process substitution:
read -a arrchar -d '' < <(fold -w1 t.txt | sort -u)