I have a variable containing a path and want to expand a glob pattern based on that path. I want to understand why my attempts don't work and what is the preferred way of doing this in bash.
EX: I want to list all text files in my home directory or only those that starts with "test". My failing attempts:
foo="~/"
echo $foo*.txt
echo ${foo}test*.txt
These results in the string outputs ~/* and ~/test*txt respectively. I have tried different versions with quotes etc. but I guess this enough to show my issue and level of understanding — I am a bash beginner. Is the issue related to tilde expansion vs. using $HOME?
Ultimately, I want to loop over these files but I ask this question to understand bash, not just get the result.
P.S. I am certain there are answers to this already out there but I've not managed to find any that have helped me understand this case. I tried to understand the general expansion order in bash but still don't understand how to apply it here.