C-shell : foreach ls cannot detect file name with dash/hyphen (-)

Viewed 243

I have a c shell script that filter for a file with condition as below:

*_[+-]*[A-D]*.txt

Example of file:

Reflow_-12_A124er.txt

My script as below:

#!/bin/csh -f

cd /data
foreach file (`ls *_[+-]*[A-D]*.txt`)
echo "file: " $file
gzip $file
end 

If i try command ls *_[+-]*[A-D]*.txt in data folder, there is output for the txt file. But if i try run the script, the script not detect the file with (-) even tough it meets the filter. Why?

1 Answers
Related