1

I've got an empty directory. The command:

for i in *.xls; do echo $i; done

return

*.xls

Could you explain why? And how to correct this please?

Thanks

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Souricier
  • 33
  • 3
  • 1
    "Why" is so `ls *.xls` says `*.xls: file not found` instead of doing the same thing as `ls` with no arguments and listing every file in the current directory (not just `.xls` files). – Charles Duffy Dec 31 '21 at 13:26
  • 1
    "How do avoid it" is covered by the linked duplicate (there are two approaches: `shopt -s nullglob` to change behavior, or making your loop run something like `[[ -e $i || -L $i ]] || continue`). There's also a `failglob` flag you can set to make a glob that doesn't match anything be an error. – Charles Duffy Dec 31 '21 at 13:27
  • I highly suggest failglob when interactive. Nullglob when not. – konsolebox Dec 31 '21 at 13:36

0 Answers0