zsh-users
 help / color / mirror / code / Atom feed
* subscript not working as "I" expected it would
@ 2023-11-04  7:08 Jim
       [not found] ` <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Jim @ 2023-11-04  7:08 UTC (permalink / raw)
  To: zsh

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-04 16:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-04  7:08 subscript not working as "I" expected it would Jim
     [not found] ` <CAN=4vMowpVVYPfkeTnwXEbUUU48UNMwPGnjGi3wWYFVkx21YdA@mail.gmail.com>
2023-11-04  8:48   ` Roman Perepelitsa
2023-11-04 16:37     ` Lawrence Velázquez

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).