-1

Sorry for the simple question, but I am new to writing bash programs.

I am trying to write this line:

for i in /etc/file*; do SOME-COMMAND $i; done

However, I need to make sure that file* can only have 2 characters after file.. Ie, "fileaa" is ok, but "fileabc" is not ok. What changes to my command would I need to make?

Thanks!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
AlexK
  • 336
  • 8
  • 21
  • 41
  • See: [What are the differences between glob-style pattern and regular expression?](https://stackoverflow.com/q/23702202/3776858) – Cyrus Sep 14 '17 at 18:59

1 Answers1

3

try changing * with ?? as follows.

for i in /etc/file??; do SOME-COMMAND $i; done

* is a greedy wild character which means it will go to match everything, on other side wild character ? means any single character, so you wanted any of 2 so ?? should help here.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93