From: Jim <linux.tech.guy@gmail.com>
To: zsh <zsh-users@zsh.org>
Subject: subscript not working as "I" expected it would
Date: Sat, 4 Nov 2023 02:08:07 -0500 [thread overview]
Message-ID: <CA+rB6GLiYbd9EO8_5vRowq09AWsQ3McCzR0D3k6GTXbzhM5m0w@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 906 bytes --]
Hi everyone,
Case: Outputting a hash from a git repository, but want it abbreviated.
This is done totally via z-shell script, without git commands.
Taking a bash/sed example and converting it to zsh.
Sorry if that is to much information.
With
print -- $(<.git/${(s.: .)$(<.git/HEAD)[2]})
I get the full 40 character hash as expected
but when I tried to output the first 9 characters
print -- ${$(<.git/${(s.: .)$(<.git/HEAD)[2]})[1,9]}
it too, returns the full 40 character hash and no warnings or error
messages.
After beating my head for a while, it dawned on me to try quoting
print -- ${"$(<.git/${(s.: .)$(<.git/HEAD)[2]})"[1,9]}
which worked, returning the first 9 characters of the hash.
Could someone explain why the quotes are needed here so hopefully
the next time I will understand. I swear zsh quoting will drive me nuts.
Thanks for putting up with me.
Regards,
Jim Murphy
[-- Attachment #2: Type: text/html, Size: 1270 bytes --]
next reply other threads:[~2023-11-04 7:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-04 7:08 Jim [this message]
[not found] ` <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com>
2023-11-04 8:48 ` Roman Perepelitsa
2023-11-04 16:37 ` Lawrence Velázquez
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+rB6GLiYbd9EO8_5vRowq09AWsQ3McCzR0D3k6GTXbzhM5m0w@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).