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

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



Hey,

if you don't put a space there then the parser thinks that this the
"${variable:-default} syntax which means "expands to the variable's
content if the variable is set and to 'default' if it is unset". Can
be seen easily with:

[0 mosu@sweet-chili ~] echo ${thisvarisnotset:-1:1}
1:1

So the '1:1' is interpreted as the 'default'. You probably never saw
that result because you were trying to extract the last character from
a string, meaning you always used a variable that was set.

Kind regards,
mosu



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