How does extglob work with shell parameter extension?

I thought I understood the use of optional in (when the shell option is enabled ) and by default in . For example, in : ?(pattern-list) bash extglob kshbash

$ shopt -s extglob
$ V=35xAB
$ echo "${V#?(35|88)x}" "${V#35}"
AB xAB

But if the prefix pattern being matched is only one ?()or one *()that introduces what I call optional patterns , it is 35not skipped if not used : ##

$ echo "${V#?(35|88)}" "${V#*(35|88)}"    # Why 35 is not left out?
35xA 35xA
$ echo "${V##?(35|88)}" "${V##*(35|88)}"  # Why is it omitted when ## is used?
xA xA

The same behavior is reported when ?(), and *()are used in the template suffix matching (using %and %%):

$ echo "${V%5?(xA|Bz)}"                   # 5xA is omitted
3
$ echo "${V%?(xA|Bz)}" "${V%*(xA|Bz)}"    # why xA is not left out?
35xA 35xA
$ echo "${V%%?(xA|Bz)}" "${V%%*(xA|Bz)}"  # xA is omitted when %% is used
35 35

bash 3.2.25, 4.1.2 4.1.6, , , , .

- ?

+2
1

@ ?, :

$> echo "${V#@(35|88)}"
xAB

$> echo "${V%@(xAB|Bzh)}"
35

+ *:

$> echo "${V#*(35|88)}"
35xAB

$>echo "${V#+(35|88)}"
xAB

, :

  • ?(pattern-list) #
  • @(pattern-list) #

  • *(pattern-list) #
  • +(pattern-list) #
+1

All Articles