0
read answer 
ans=${answer::1}

What does the operator :: do?

I thought it allowed touppercase a letter but im not sure

Plata
  • 1
  • Does this answer your question? [What are double colons :: in a shell script?](https://stackoverflow.com/questions/44558080/what-are-double-colons-in-a-shell-script) – koto Nov 08 '22 at 11:20
  • @koto No, that's a completely different context. – tripleee Nov 08 '22 at 11:28

1 Answers1

3

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

glenn jackman
  • 238,783
  • 38
  • 220
  • 352