Glob拡張:?(リスト)、*(リスト)、+(リスト)、および@(リスト)の構文の違いは何ですか?

Glob拡張:?(リスト)、*(リスト)、+(リスト)、および@(リスト)の構文の違いは何ですか?

グローバル拡張について読んだ後に質問があります。

使用後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

おすすめ記事