Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Getting a particular char
- X-seq: zsh-users 7804
- From: DervishD <raul@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Getting a particular char
- Date: Fri, 6 Aug 2004 12:55:41 +0200
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Pleyades
Hi all :)
First of all, my excuses because although this is a shell related
question, is not exactly a zsh related question. Is more about
portability, about how to implement a zsh facility in portable shell.
If I want to get the character number 'n' from a parameter, in
zsh I do something like: $parameter[n]. Easy, short... and non
portable.
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.
So I'm implementing it like that:
# Dirty and ugly hack, needs some polishing...
# First we get rid of all characters at the beginning
while [ ${#parameter} -gt n ]
do
parameter=${parameter#?}
done
# Now, get rid of the characters after
# the one we are interested in
while [ ${#parameter} -gt 1 ]
do
parameter=${parameter%?}
done
I would like another ideas, shorter, faster, or simply less ugly,
and it must be portable, so no zsh tricks :(( If you could please
help me... Thanks a lot in advance.
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