Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

subscript not working as "I" expected it would



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


Messages sorted by: Reverse Date, Date, Thread, Author