Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

$match size limit, suspicious (#B) behavior



Hello,
turns out $match has a size limit of 9:

% a='abcdefghijk'; [[ "$a" = (#b)(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k) ]]
&& echo "match[9]: $match[9], match[10]: $match[10]"
match[9]: i, match[10]:

Which can be to some extent worked around with (#B):

% a='abcdefghijk'; [[ "$a" =
(#b)(a)(b)(c)(d)(#B)(e)(#b)(f)(g)(h)(i)(j)(k) ]] && echo "match[9]:
$match[9], match[10]: $match[10]"
match[9]: j, match[10]:

Now the difficult part – but just count the parentheses before and
after (#B) – my input is:

mybuf='if [[ "$mybuf" =
(#b)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi'

Now code that matches either $var, ${var}, \$:

while [[ "$mybuf" =
(#b)([^\$\\]#)((#B)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1)[}])|([\\][\'\"\$]))(#b)(*)
]]; do
    echo "Got: ${match[2]}"
    echo "Match 1: ${match[1]}"
    echo "Match 2: ${match[2]}"
    echo "Match 3: ${match[3]}"
    echo "Match 4: ${match[4]}"
    echo "Match 5: ${match[5]}"
    echo "Match 6: ${match[6]}"
    echo "Match 7: ${match[7]}"
    echo "Match 8: ${match[8]}"
    echo "Match 9: ${match[9]}"
    mybuf="${match[8]}"
  done

Output is:

Got: $mybuf
Match 1: if [[ "
Match 2: $mybuf
Match 3:
Match 4:
Match 5:
Match 6:
Match 7:
Match 8: " = (#b)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi
Match 9:

Got: \$
Match 1: " = (#b)(
Match 2: \$
Match 3:
Match 4:
Match 5:
Match 6:
Match 7: \$
Match 8: ([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi
Match 9:

"Match 8: .." is: "the rest", i.e. (*). "Match 1: .." is: "before".
"Match 2: .." is the $var, ${var} or \$.

The problem: (#B) should have disabled all parentheses from where it
is placed, and "Match 8: ..." should be at "Match 3: ..". Also, "Match
7: .." has the same value as "Match 2: ..", which seems to be a
problem.

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author