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

Re: Parameter Expansion pattern compatibility



On Wed, Dec 10, 2008 at 07:13:27PM +0100, @ Rocteur CC wrote:
[...]
>> That's ksh globbing syntax (except for the outer (...)). To
>> enable it in zsh, you need setopt kshglob.
>>
>> The zsh equivalent of @(...) is (...), the equivalent of *(x) is
>> x# (with extendedglob).
>>
>> ~$ setopt kshglob; echo ${userId##[pPRrTt]@([0-9]|[a-z])*([0-9])}
>> btu btu btu eb41 bt2 jro dri
>>
>> ~$ setopt nokshglob extendedglob; echo 
>> ${userId##[pPRrTt]([0-9]|[a-z])[0-9]#}
>> btu btu btu eb41 bt2 jro dri
>
>
> OUCH, I tried those with no success so the problems were setopt and the 
> outer ()
>
> I did try kshglob and I didn't think to remove the outer bracket.  (I've 
> just tried it on my home system and it works with the outer bracket ?

It works in zsh (as (...) are the same as ksh's @(...)), but
wouldn't in ksh. I'd expect you to get an error in ksh.

> This all happens in a massive script so I could put setopt kshgob within 
> the function.

When zsh is called as "ksh", the kshglob option is activated.

> As always Stephane, thanks very much .. I really appreciate your help all 
> the time!
>
> As an aside note, how would one do this in standard zsh without the kshglob 
> ?
[...]

As I said:

The zsh equivalent of @(...) is (...), the equivalent of *(x) is
x# (with extendedglob).

~$ setopt nokshglob extendedglob; echo ${userId##[pPRrTt]([0-9]|[a-z])[0-9]#}
btu btu btu eb41 bt2 jro dri

You need the extendedglob.

Note that bash's extglob is actually a subset of ksh's extended
globbing operators. zsh's kshglob also is a subset, it doesn't
include the latest ones from latest versions of ksh93. zsh's
extendedglob has a few operators which ksh93 doesn't have such
as <x-y> for matching numbers.

-- 
Stéphane



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