On Nov 17, 2:56pm, Ray Andrews wrote:
} Subject: Re: ${var: -1:1} vs. ${var:-1:1}
}
} > 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".
} >
} > 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.
} >
} I see. But it's still lousy syntax IMHO.
Well, the var:-word syntax long predates :N:M for string slicing. Zsh
actually can (and always has) used just ${var[-1]} for the last character
of a string, the :N:M syntax was invented by bash and merely adopted by
zsh for compatibility.