I'm trying to refresh my bash scripting skills. I got stuck on the dumbest thing:
for f in "$(ls)"; do
[[ $f == *.txt ]] && printf "%s\n" "$f"
done
What is wrong with this loop? I'm simply trying to print all the .txt files in the current dir. It seems that pattern match is wrong..
ls(and what to do instead)?. Then you don't need a loop for that,ls *.txtwill do. Also this. – schrodingerscatcuriosity Mar 28 '21 at 00:28set -xto see the command being executed after expansions will likely be revealing. – fra-san Mar 28 '21 at 00:59ls; 2) the whole list of files matches the pattern*.txtif the last file name ends in.txt, no matter what the other file names are. – fra-san Mar 28 '21 at 20:30