-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
  • 349,597
  • 67
  • 533
  • 578
MirrG
  • 406
  • 3
  • 10

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
  • 21,664
  • 5
  • 41
  • 68