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

Re: Getting a particular char



    Hi all :)

 * DervishD <raul@xxxxxxxxxxxx> dixit:
>     If I want to get the character number 'n' from a parameter
[...]
>     So I change it to something like 'expr substr $parameter n 1'.
> This has some problems, like '$parameter' needing some tweaking so
> 'expr' doesn't whine because it starts with '(', '+', etc. or it is
> something like the word 'match'. But all that is not important,
> because the 'substr' expression is not SUSv3 compliant, so I cannot
> do that neither.

    Finally I did this way (thanks to Paul Eggert, coauthor of GNU
coreutils, for the help):

    expr "x$parameter" : ".\{n\}\(.\)"

    Where 'n' is the index of the character we want. Easy and fully
SUSv3 compliant, where {N} is a valid BRE for repetition.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



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