-4

I'm writing a shell script, and it also has to check if a file with a certain extension exists in a different directory. I'm running an ls command like this:

TEMPLATE_FOLDER="$HOME/Downloads/" # Folder to check
file="py" # Extension only
amount_files=$(ls -1 "${TEMPLATE_FOLDER}*.${file}" 2>/dev/null | wc -l) # How many files in the directory

It keeps telling me that ls: /Users/hussein/Downloads/*.py: No such file or directory even though when I copy that exact path into the terminal itself, it works perfectly fine.

If anyone can help with this, I would appreciate it very much.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hussein Esmail
  • 353
  • 5
  • 21

1 Answers1

1
ls -1 "${TEMPLATE_FOLDER}*.${file}"

Globs are not expanded if they're quoted. Try:

ls -1 "${TEMPLATE_FOLDER}"*."${file}"
John Kugelman
  • 349,597
  • 67
  • 533
  • 578