Glob 확장: ?(list), *(list), +(list) 및 @(list) 간의 구문 차이점은 무엇입니까?

Glob 확장: ?(list), *(list), +(list) 및 @(list) 간의 구문 차이점은 무엇입니까?

전역 확장에 대해 읽은 후 질문이 있습니다.

사용 후 shopt -s extglob,

다음의 차이점은 무엇인가요?

?(list): Matches zero or one occurrence of the given patterns.

*(list): Matches zero or more occurrences of the given patterns.

+(list): Matches one or more occurrences of the given patterns.

@(list): Matches one of the given patterns.

예, 위에 첨부된 설명을 읽었지만 실용적인 목적으로 *(list)보다 ?(list)를 선호하는 경우는 보이지 않습니다. 즉, 나는 아무런 차이가 없다고 본다.

나는 다음을 시도했습니다 :

$ ls
> test1.in test2.in test1.out test2.out`

$ echo *(*.in)
> test1.in test2.in

$ echo ?(*.in)
> test1.in test2.in

설명에서만 $ echo ?(*.in)출력이 되기를 바라지 test1.in만 그렇지 않은 것 같습니다. 그렇다면 이것이 사용되는 확장 전역 유형에 어떤 영향을 미치는지 예를 들어줄 수 있는 사람이 있습니까?

원천:http://mywiki.wooledge.org/BashGuide/Patterns#Extended_Globs

답변1

$ shopt -s extglob
$ ls
abbc  abc  ac
$ echo a*(b)c
abbc abc ac
$ echo a+(b)c
abbc abc
$ echo a?(b)c
abc ac
$ echo a@(b)c
abc

답변2

"1회 이상 발생"은 1회 이상 발생을 의미합니다.동일한파일 이름, 하나 이상의 파일 이름이 일치하지 않습니다. foo?(.in).x일치 항목 foo.in.xfoo*(.in).x일치 해야 합니다.foo.in.in.x

관련 정보