From: Jim <linux.tech.guy@gmail.com>
To: zsh-users@zsh.org
Subject: End Index number not what I expected
Date: Tue, 6 Dec 2016 11:09:39 -0600 [thread overview]
Message-ID: <CA+rB6GLXS6Tmtki4ns2vejy_WU79UcmCZZzGYNX71d5+Znq5fg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]
Hello List,
zsh version: 5.2
So far, searches on the web have not returned a satisfactory
answer. If I missed the answer, shame on me and sorry for
wasting you time.
The script I'm working on globs a bunch of file names then
uses portions of the file names. As with most things in
UNIX/Linux there are multiple ways of doing things, zsh is no
exception. While trying different approaches to the task I ran
into an index issue I don't understand. Using the parameter
expansion flags (SB) and (SE) to find the beginning and end
of a match I was surprised when the ending index returned the
end of the match + 1.
The man page states:
B Include the index of the beginning of the match in the result.
E Include the index of the end of the match in the result.
Logic to me would be, if the B flag returns the index of the first
character of the match, then the E flag should return the index
of the last character of the match, not +1.
Am I missing something here?
Alternately using the conditional expression
"string =~ regexp", the integer parameters MBEGIN and MEND
work as expected.
Also in researching this I found an example of using the E flag.
The example uses a variable with a string of 10 characters,
yet using the (SE) flags the match returned an index of 11.
Should a returned index be larger the the length of the variable?
Again, just trying to understand what I'm missing here.
Thanks in advance for your help.
Sincerely,
Jim
next reply other threads:[~2016-12-06 17:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-06 17:09 Jim [this message]
2016-12-06 20:16 ` Peter Stephenson
[not found] ` <20161206201629.2970ef18__5617.78782071105$1481055469$gmane$org@ntlworld.com>
2016-12-10 14:56 ` Daniel Shahaf
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=CA+rB6GLXS6Tmtki4ns2vejy_WU79UcmCZZzGYNX71d5+Znq5fg@mail.gmail.com \
--to=linux.tech.guy@gmail.com \
--cc=linuxtechguy@gmail.com \
--cc=zsh-users@zsh.org \
/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).