Article 5F730 Bash Spinner - Question about syntax

Bash Spinner - Question about syntax

by
Arct1c_f0x
from LinuxQuestions.org on (#5F730)
Observe, if you will, the code below.

Code:# Bash, with GNU sleep
spin() {
local i=0
local sp='/-\|'
local n=${#sp}
printf ' '
sleep 0.1
while true; do
printf '\b%s' "${sp:i++%n:1}"
sleep 0.1
done
}
The code above creates a spin animation. I know how to recreate it in several ways using different syntax, but there are two lines that I don't completely understand

1st:

'local n=${#sp}' Does this mean set variable "n" to the number of elements in local array "sp" ?

2nd:

In the printf statement that references the sp char array; What functions do the colons ':' serve?

Thanks.latest?d=yIl2AUoC8zA latest?i=RMKzSAla5I4:Dt91onuB89U:F7zBnMy latest?i=RMKzSAla5I4:Dt91onuB89U:V_sGLiP latest?d=qj6IDK7rITs latest?i=RMKzSAla5I4:Dt91onuB89U:gIN9vFwRMKzSAla5I4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments