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 *.txt
will do. Also this. – schrodingerscatcuriosity Mar 28 '21 at 00:28set -x
to 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*.txt
if the last file name ends in.txt
, no matter what the other file names are. – fra-san Mar 28 '21 at 20:30