zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Getting a particular char
Date: Fri, 6 Aug 2004 12:55:41 +0200	[thread overview]
Message-ID: <20040806105541.GE24158@DervishD> (raw)

    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/


             reply	other threads:[~2004-08-06 10:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-06 10:55 DervishD [this message]
2004-08-10 11:51 ` DervishD
2004-08-06 11:24 Sean Johnston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040806105541.GE24158@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).