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

${var: -1:1} vs. ${var:-1:1}



I just wasted an hour trying to extract the last character from a string. My problem was that I did: "${var:-1:1}" and didn't put a space in front of the minus sign. Bash has the same problem, so this isn't a zsh specific issue, but I'd feel a lot better if someone could explain why that space is necessary. All the shells seem to have these little gotchas with spaces. Sometimes they're ignored, sometimes mandatory and sometimes forbidden. It sure is a PITA. I can only compare this to C, where such problems are nonexistent. If there is some sort of master plan governing spacing, I'd sure like to know what it is.

Thanks, sorry to bitch.



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