read answer
ans=${answer::1}
What does the operator :: do?
I thought it allowed touppercase a letter but im not sure
read answer
ans=${answer::1}
What does the operator :: do?
I thought it allowed touppercase a letter but im not sure
Let's see what it does:
$ answer="abcde"
$ echo ${answer::1}
a
It seems to print the first letter. Why is that?
The expansion ${var:offset:length}
gives a substring starting at the zero-based offset
for length
characters.
Both offset
and length
are arithmetic expressions, and apparently an empty offset evaluates as zero.
Full details at 3.5.3 Shell Parameter Expansion