-1

I have many files with pattern name:

N.apple(d).log

e.g. 001.apple(d).log, 002.apple(d).log, etc.

The problem is when I am trying to do something with the files in a bash script, there is always an error 'No such file or directory' even with escaped brackets:

for i in $(ls my_folder); do file=$(echo $i | sed 's/(/\\(/g' | sed 's/)/\\)/g') ; head -1 my_folder/$file; done

Thanks for any tips

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
MirrG
  • 366
  • 2
  • 9

1 Answers1

1

Use quotes. Also, don't use ls when the shell can expand the wildcards just fine already.

for i in my_folder/*; do head -1 "$i"; done
Tanktalus
  • 20,876
  • 5
  • 42
  • 66