简体   繁体   中英

Selecting a string of a specific length in one-line bash regex

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM