7

I have a bash script where $DIR is a directory name that may contain spaces.

This:

rm "$DIR/*.MOV"

gives the error "No such file or directory". There is no file literally named "*.MOV"; I want the * to expand into multiple arguments - one per matching filename.

Eg:

rm some\ folder/foo.MOV some\ folder/bar.MOV

How can I do this?

Cyrus
  • 5,751
Nathan Long
  • 27,435

2 Answers2

11

Quoting prevents globbing. Try this with GNU bash:

rm "$DIR"/*.MOV
Cyrus
  • 5,751
-1

A workaround:

for FILE in `ls "$DIR" | grep .MOV`; do
  rm "$DIR/$FILE"
done
Nathan Long
  • 27,435